Learning C: day 1

by chashkakefira

Okay, today I had not so many time to program: school, dishes, etc.

So, today I wrote only 29 lines of code. Not so many, but I think, for the first day of learning this is not bad.

I wrote simple calculator app, which takes to number and perform specified operator on them.

So, here are my 29 lines of code:

#include <stdio.h>

    int main(){
        float result;
        float curr;
        float next;
        char operator;
    
        scanf("%f %c %f", &curr, &operator, &next);
    
        switch (operator){
            case '+': result = curr+next; 
                break;
            case '-': result = curr-next; 
                break;
            case '/': 
                if (next != 0){
                    result = curr/next;
                } else {
                    puts("ZeroDivision error!");
                    return 1;
                }
                break;
            case '*': result = curr*next; 
                break;
        }
        printf("%f\n", result);
        return 0;
    }
    
Link to GitHub repository

So, my future plans on this program is to improve it, so it can deal with "complex" things like

(1+1)*(1+1) or (1+ 2 / 1) * (2 + 3 /2) / ...

Also, I forgot about square and power. Will be added tomorrow.

That's all for today, see you tomorrow.