Hello,
I need some help with a calculator I need to create in C++ for my coursework.
Firstly, the user needs to be able to select an operator from +,-,*,/,%,n2
Next, they will input number one then number two, and the answer will be given depending on which operator was selected.
I managed to get a basic one working with case/swtich statements (I think thats what they are?) but the problem is, the design says it must include at least
2 procedures.
Can someone try to help me with this? Ill paste my code below of what i've got so far, but I just need to know where to put
procedures?
Also, i'm not the best at variables either so I don't know if everything is exactly right.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
using namespace std;
int firstnumber;
int secondnumber;
int result;
char op;
int main()
{
cout<<"Please select an Operator for the calculation: + or -\n";
cin>>op;
cout<<"Please enter the first number: ";
cin>>firstnumber;
cout<<"\n";
cout<<"Please enter the second number: ";
cin>>secondnumber;
cout<<"\n";
switch(op)
{
case'+':
result=firstnumber+secondnumber;
cout<<"Answer: "<<result<<endl;
break;
case'-':
result=firstnumber-secondnumber;
cout<<"Answer: "<<result<<endl;
break;
}
system("PAUSE");
}
|
Any help would be greatly appreciated! Thanks guys