#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void run_calc();
void scandata(char *op, double * operand);
void do_next_op(char op, double operand, double *akku);
int main()
{
run_calc();
return 0;
}
void run_calc(){
double akku = 0, operand = 0;
char op, answer;
printf("Press enter to use the calculator");
printf("\n");
scanf("%c", &answer);
while(answer='q'||answer!='Q');
{
if(answer=='q'||answer=='Q')
{
printf("The last result was %1.2f\n", akku);
exit(0);
}
else if (answer=='h'||answer=='H')
{
printf("%s\t%s\n", "+" , "add");
printf("%s\t%s\n", "-" , "subtract");
printf("%s\t%s\n", "*" , "multiply");
printf("%s\t%s\n", "/" , "divide");
printf("%s\t%s\n", "^" , "power");
printf("%s\t%s\n", "q" , "quit");
}
else
{
printf("Enter an operator (+,-,/,#,^,*) and optional operand.Enter 'h' for help. Enter 'q' to exit the program.");
scandata(&op, &operand);
do_next_op(op, operand, &akku);
printf("Result so far is: %1.2lf \n", akku);
printf("\n");
}
}
}
void scandata(char *op, double *operand) {
scanf("%c", op);
scanf ("%lf", operand);
}
void do_next_op(char op, double operand, double *akku)
{
switch(op)
{
case '+': *akku += operand; break;
case '-': *akku -= operand; break;
case '*': *akku *= operand; break;
case '/': *akku /= operand; break;
case '#': *akku = sqrt(*akku); break;
case '^': *akku = pow(*akku,operand); break;
case '%': *akku *= -1; break;
case '!': *akku = 1 / *akku; break;
case '@': *akku = log(*akku); break;
case 'q': printf(" The final value of akku is %1.2lf \n", *akku); exit(0);
}
}
After i run the program and press enter or any letter. it just stucks . can someone help me please? This program is a calculator that i try to do it. This is for my homework which is due to next week. I am still new this programming. i need help and alot of improvement. Can someone point it out what i did wrong?
I think there is something wrong in run_Calc but i dont know what is wrong with it