The calculation will be based on the letter the user inputs (e or E sets the number as the accumulator, t or T is suppose to terminate, a or A is addition, m or M is multiplication, etc.). The problem I am having is that it doesn't matter what number i put in it just prints out 0.00 and the loop never ends. The program should go through once do the calculation based off the operator and then wait for the users next input.
#include <stdio.h>
#include <math.h>
void main (){
double accum;
double number;
char operator;
scanf ("%lf%c", &number, &operator);
while (operator != 't' && operator != 'T'){
if (operator == 'e' || operator == 'E')
printf ("= %0.2lf\n", accum = number);
else if (operator == 'a' || operator == 'A')
accum += number;
else if (operator == 's' || operator == 'S')
accum -= number;
else if (operator == 'm' || operator == 'M')
accum *= number;
else if (operator == 'd' || operator == 'D')
accum /= number;
else if (operator == 'p' || operator == 'P'){
accum = pow(accum, number);
printf ("= %0.2lf\n", accum);}
else{
printf ("invalid command\n");
scanf ("%lf%c", &number, &operator);}
}
}
This post has been edited by Worr: 07 October 2009 - 01:31 PM

New Topic/Question
Reply



MultiQuote




|