sorry , didn't notice the '&', and now is how to make the result repeated to another operation
eg.
Enter an operator [^,*,/,+,-,q (quit): +
Enter a number to calculate for: 9
+ 9.00
The result so far is + 9.00
Enter an operator [^,*,/,+,-,q (quit): +
Enter a number to calculate for: 9
+ 9.00
The result so far is 18.00
latest code
Code:
#include <stdio.h>
#include <math.h>
void scan_data(char *op1p, double *num1p);
void do_next_op(char op1, double num1, double *accum);
void main()
{
double num1;
char op1;
double accum;
accum=0;
printf("Hit enter to turn the calculator on");
getchar();
do{
scan_data(&op1, &num1);
do_next_op(op1, num1, &accum);
}
while (!(op1 == 'q'));
}
void scan_data(char *op1p, double *num1p)
{
printf("\nEnter an operator [^,*,/,+,-,q (quit)]: ");
scanf(" %c",op1p);
printf("Enter a number to calculate for: ");
scanf("%lf",num1p);
printf("%c %.2lf \n",*op1p,*num1p);
printf("The result so far is %.2lf \n",*num1p);
}
void do_next_op(char op1, double num1, double *accum)
{
switch(op1)
{
case '+':
{
*accum = *accum + num1;
break;
}
case '-':
{
*accum = *accum - num1;
break;
}
case '*':
{
*accum = *accum * num1;
break;
}
case '/':
{
*accum = *accum / num1;
break;
}
case '^':
{
*accum = pow(*accum, num1);
break;
}
case 'q':
case 'Q':
{
printf("The final result was %f",*accum);
break;
}
}
}