# Aritmetic string

• 12-18-2002
666cos
Aritmetic string

now that thats out of the way.........

im taking my first C++ class and i have no idea how you
would implement 9+8*5-(6+7) = sum

basically i want to enter this string and press enter and it should give me an answer.

i have really no c++ experience so if any of you can email me some code i would really appreciate it.

ps i use visual c++ microsoft
• 12-18-2002
Sebastiani
Quote:

im taking my first C++ class and i have no idea how you
would implement 9+8*5-(6+7) = sum.
Hence the term "learning process". We have no problem discussing ideas like this. But so far, your idea stinks...perhaps you should put some more thought into it. :confused:

Quote:

basically i want to enter this string and press enter and it should give me an answer.
Odd. That's what we all want out of a program.

Quote:

i have really no c++ experience so if any of you can email me some code i would really appreciate it.
Sure, post your code and I'll be glad to email it back to you.

P.S. - We don't do your homework here.
• 12-18-2002
joshdick
Don't expect anyone around here to do it for you. If that's what you're looking for, try this site: http://www.wedoyourhomework.com
• 12-18-2002
666cos
#include <iostream.h>

int main()
{
// local variables

int First ;
int Second ;
char ch ;
// print directions

cout << "\nEnter a series of single-digit numbers " << endl
<< "each followed by an arithmetic operator." << endl
<< "Enter the = operator to to compute your result." << endl
<< endl ;

cin >> First >> ch ;

while ( ch != '=' )
{
cin >> Second ;
switch ( ch )
{
case '+' :
First = First + Second ;
break ;
case '-' :
First = First - Second ;
break ;
case '*' :
First = First * Second ;
break ;
case '/' :
if ( Second != 0 )
First = First / Second ;
else
cout << "Division by zero.\n" ;
break ;
default :
cout << "Input error.\n" ; return 1 ;
}
cin >> ch ;
}

cout << "Result: " << First << endl << endl ;

return 0 ;
}

i cant figure out how to put cos, tan, and sin, or brakets
• 12-18-2002
Lurker
You have at least one logic error, if you entered the equation:

9+8*5

the answer should be 49 (9+40 = 49), but with your calculation it will be 85 (17*5 = 85).