Discussion in 'C++' started by 2007160935, Mar 6, 2009.

1. ### 2007160935New Member

Joined:
Mar 6, 2009
Messages:
38
0
Trophy Points:
0
Occupation:
..
Location:
..
anyone can show me a codes for calculator which determines a space, a letters and symbols

for example:
Enter a equations:
1+2=3
1 + 3 = 3
1 + b = invalid character
1 + * = invalid character

2. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
No but I'll help you figure it out. What have you got so far and where are you stuck?

3. ### 2007160935New Member

Joined:
Mar 6, 2009
Messages:
38
0
Trophy Points:
0
Occupation:
..
Location:
..
what I mean is, if anyone tell me how's that? or show me the codes for better improvements

Check this out!
I just want to improve this codes :shy:
Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
int  left, right;   // Operands
char oper;          // Operator
int  result;        // Resulting value

while (cin >> left >> oper >> right) {
switch (oper) {
case '+': result = left + right;
break;
case '-': result = left - right;
break;
case '*': result = left * right;
break;
case '/': result = left / right;
break;
default : cout << "Bad operator '" << oper << "'" << endl;
continue;  // Start next loop iteration.
}
cout << result << endl << endl;
}

return 0;
}

Last edited by a moderator: Mar 8, 2009
4. ### 2007160935New Member

Joined:
Mar 6, 2009
Messages:
38
0
Trophy Points:
0
Occupation:
..
Location:
..
1 + 3 = 4, suck i didnt notice what im typing xD:

Joined:
Jul 12, 2004
Messages:
15,337
377
Trophy Points:
83
There is nothing much but if you want to add some complex Bodmas calculation you would need to do a lot.

Joined:
Aug 6, 2004
Messages:
3,009