# Calculator Program

• 03-16-2002
ProgrammingDlux
Calculator Program
...Okay, I had to do this calculator program and this is what I've done so far..how can I make it so that when I press "E"..the program stops and "enter a number and operator sign: " doesn't display? I'm not sure if I wrote it the most efficient way possible..any advice?

#include <iomanip.h>
#include <stdlib.h>

main()
{ float Num, Accum; char Operator;

cout<<"\n Printing Calculator Program ";
cout<<"\n-----------------------------";

while(Operator != 'E' || Operator != 'e')
{ cout<<"\n\n Enter a Number and Operator Sign: + - * / S E: ";
cin>>Num; cin>>Operator;

cout.setf(ios::floatfield, ios::showpoint);
cout.setf(ios::fixed);
cout<<setprecision(4);

switch(Operator)
{ case 'S': case 's':
Accum=Num;
cout<<"\nAccumulator = "<<Accum;
break;

case '+':
Accum=Accum+Num;
cout<<" = "<<Accum;
break;

case '-':
Accum=Accum-Num;
cout<<" = "<<Accum;
break;

case '/':
Accum=Accum/Num;
cout<<" = "<<Accum;
break;

case '*':
Accum=Accum*Num;
cout<<" = "<<Accum;
break;
}
}

system("PAUSE");
return 0;
}
• 03-16-2002
ProgrammingDlux
any suggestions would be great
• 03-16-2002
initialize Operator to something other than E or e BEFORE the loop starts and

make the while conditional && instead of ||. Since Operator cannot be both E and e at the same time your conditional is always true.
• 03-16-2002
neandrake
don't you need <iostream.h> for cout and cin???