C++ Calculator Help PLEASE!!!!?
I am so sick this week.... DO NOT GET A FLU SHOT!
It was a very big mistake.
Im having a very hard time concentrating on this program, THis is the assignemt PLease help me.
In this assignment you must implement a simple integer calculator. The arithmetic functions of addition, subtraction, multiplication, modulus, and division are to be supported. The calculator contains an Accumulator that stores the current result. The Accumulator is also involved with each operation. Make sure that you define a class for this program.
Once started, the Accumulator is set to zero, and the operation to be performed is set to addition (+). The program then repeats the following steps:
Request and Accept a number
Apply the stored operation (Acc op= number)
Request and Accept the next operation
This process repeats until the equals sign (=) is entered as an operation. At this point, the Accumulator contents are displayed and the calculator is reset (Accumulator set to zero and operation to +).
The following characters are legal operations:
+, -, *, %, /, =, and !.
The ! is treated the same as =, but causes the program to terminate. Any other characters entered as operations should cause a brief error message and should be ignored. Division by zero errors cause a reset.
Sample run:
SuperCalculator at you service!
------
Input: 10
Operation: *
Input: 2
Operation +
Input: -5
Operation: =
Result: 15
------
Input: 12
Operation: /
Input: 0
**Division by zero - start over
------
Input: 12
Operation: %26gt;
**Invalid operation - ignored
Operation: /
Input: 5
Operation: =
Result: 2
------
Input: 10
Operation: %
Input: 6
Operation: *
Input: 3
Operation: !
Result: 12
------
SuperCalculator Off!
1 hour ago - 3 days left to answer.
Report It
Visual C++ Calculator help PLEASE !!!! has to be written in visual c++?
you can't "use" the operation they input you have to do something like (psuedo code here)
get input
take firstNumber
take sign
take secondNumber
Now what you have to do is check the sign
if(sign == '+')
result = firstNumber + secondNumber
else if (sign == '-')
result = firstNumber - secondNumber
else if (sign == '*')
result = firstNumber * secondNumber
/*Keep doing that for all the functions you have to do.*/
/*[other valid cases here]*/
else /*random junk entered by user*/
Output this junk isn't valid or some other brief error message.
Reply://Hey U can also compile and run it in visual c++
#include%26lt;iostream.h%26gt;
#include%26lt;stdio.h%26gt;
int main()
{
int acc=0,input;
char oper='+';
printf("-----\n");
while(oper!='!')
{
cout%26lt;%26lt;"input: ";
cin%26gt;%26gt;input;
switch(oper)
{
case '+':
acc+=input; break;
case '-':
acc-=input; break;
case '*':
acc*=input; break;
case '/':
if(input==0)
{
cout%26lt;%26lt;"**divide by zero - start over\n-----\n";
acc=0;
oper='+';
}
else
acc/=input; break;
case '%':
if(input==0)
{
cout%26lt;%26lt;"**divide by zero - start over\n-----\n";
acc=0;
oper='+';
}
else
acc%=input; break;
default:
acc+=input; break;
}
while(1)
{
cout%26lt;%26lt;"Operation: ";
cin%26gt;%26gt;oper;
if(oper!='+'%26amp;%26amp; oper!='-' %26amp;%26amp; oper!='*'%26amp;%26amp; oper!='/'%26amp;%26amp; oper!='%'%26amp;%26amp; oper!='='%26amp;%26amp; oper!='!')
{
cout%26lt;%26lt;"\nInvalid Operation - ignored";
}
else break;
}
if(oper=='=' || oper=='!')
{
cout%26lt;%26lt;"Result: "%26lt;%26lt;acc%26lt;%26lt;"\n-----\n";
acc=0;
oper='+'; // default
if(oper=='!')
{
cout%26lt;%26lt;"\nSuper Calculator off";
break;
}
}
}
return 0;
}
secret garden
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment