here's a simple c calculator:
...but i have some problems with it.. can any1 please help me?Code:#include<stdio.h> #include<conio.h> #include<math.h> int main() { double num1, num2, result; char operator; clrscr(); printf("Enter two numbers and an operator in this form: \n"); printf("<number1> <operator> <number2> (e.g. 7 + 4) \n"); scanf("%lf %c %lf", &num1, &operator, &num2); if (operator == '+') { result = num1 + num2; printf("%g %c %g = %g\n", num1, operator, num2, result); } else if (operator == '-' ) { result = num1 - num2; printf("%g %c %g = %g\n", num1, operator, num2, result); } else if (operator == '*' ) { result = num1 * num2; printf("%g %c %g = %g\n", num1, operator, num2, result); } else if (operator == '/' ) { result = num1 / num2; if (num1||num2 == 0) printf("Cannot divide with zero!"); printf("%g %c %g = %g\n", num1, operator, num2, result); } else printf("Invalid operator used."); return 0; }
...i wanna use the switch() statement instead of using if's and else if's, but i don't know much about it...
...also, i want this program to run in an infinite loop (...while(1) or for(;...), until the user presses a hot-key.. like Ctrl-Q or Alt-X... but, sadly, i dnt also know how... srry..
..thanks in advance for your help... i'll appreciate them for sure... hehehe... -_+![]()



LinkBack URL
About LinkBacks
...), until the user presses a hot-key.. like Ctrl-Q or Alt-X... but, sadly, i dnt also know how... srry..



