GetOperator() and GetOperand() functions

My question is how can i implement code into this that uses a GetOperator() and a GetOperand() function to call into my main function to see if its bad input or not? This is what i have so far....


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
#include<iostream>
#include<string>
using namespace std;

int main()
{
float total, num;
char operat;
total=0;
do
{
cout<<"Please input your expression starting with an operand and type in '=' when completed ";
cin>>num;
if(operat=='-')
{
total=total-num;
}
else
{
total=total+num;
}
cout<<"Please insert a minus or addition operator ";
cin>>operat;
}while(operat!='=');
cout<<total;
return 0;
}
Last edited on
Please do not post the same question multiple times.
http://www.cplusplus.com/forum/beginner/207381/
You need to elaborate. What exactly is your problem? What have you tried, and how did it fail?
@mbozzi - When someone points out a thread is a duplicate, please keep your comments to the original (linked) thread. Having comments in multiple threads is confusing and a waste of time.
Fair enough. :)
Topic archived. No new replies allowed.