Hi, that's a nice little program!
A few notes:
1)
Code:
float result;
float first;
float second;
char started;
char operation;
int main(int argc, char** argv) {
result = 0;
first = 0;
second = 0;
started = 'n';
Why don't you initialize the variables when you declare them?
Code:
float result = 0;
float first = 0;
float second = 0;
char started = 'n';
char operation;
Also, it does not really matter here, but I would make these variables local (maybe just my personal taste). I allways try to declare all variables in the smallest scope possible. In this case,
result,
first and
second and
operation could very well be declared even inside of the
while loop.
2)
Code:
started = 'n';
while (1) {
if (started == 'n') {
printf("Type all your equations in the correct form, examples: "
"2 + 2, 4 * 4, and so on, one space between the first number, the operation symbol, and the second number.\n");
started = 'y';
continue;
}
...
}
I don't really understand this. If you want this to be done only in the first iteration, why don't you just put it out of the loop? That would also save you the need for the
started variable:
Code:
printf("Type all your equations in the correct form, examples: "
"2 + 2, 4 * 4, and so on, one space between the first number"
", the operation symbol, and the second number.\n");
while (1) {
...
3)
Code:
case 'q':
break;
case 'Q':
break;
default:
break;
No reason to put all those in your code when the result is the same. Just the
default would suffice.
Also, this code will also not work as expected, since the
break statement will take you out of the
switch, but not out of the
while loop.