Simple integer Expression!

I

ianenis.tiryaki

well i wrote this code but it doesn't work and shows me bunch of
syntax if you can help me out finding them i would appreciate it!

the program should do simple calculations and no parenthesis are
allowed.so it is basically really simple but i am new at programming
and not sure about my code. Thank you!

here is my code:

#include <iostream>
#include <string>
#include <iostream.h>
using namespace std;

void main()

{
int b, c ; //declearing the variables
int reply;
int output;


cout << "Please enter 2 numbers" << endl;
cin >> b >> c;
cout <<"The Value of b: " << b << endl;
cout <<"The Value of c: " << c << endl;
cout << "please type '+' for abstraction, '-' for substraction,
'/' for division, and '*' for multipication"<< endl;
cin >> reply >>;

if (reply= + ) {
output = b + c;
}

else if (reply = - ) {
output = b - c;
}

else if (reply = / ) {
output = b / c;
}
else if (reply = * ) {
output = b * c;
}

cout << "output: " << output << endl;

// This section stops the program 'flashing' off the screen.

cout << "Press q (or any other key) followed by 'Enter' to quit:
";
cin >> reply;
return 0;

}
 
I

Ian Collins

well i wrote this code but it doesn't work and shows me bunch of
syntax if you can help me out finding them i would appreciate it!

the program should do simple calculations and no parenthesis are
allowed.so it is basically really simple but i am new at programming
and not sure about my code. Thank you!

here is my code:

#include <iostream>
#include <string>
#include <iostream.h>

Loose this.
using namespace std;

void main()
main returns int.
{
int b, c ; //declearing the variables

Superfluous comment.
int reply;

Wrong type.
int output;


cout << "Please enter 2 numbers" << endl;
cin >> b >> c;
cout <<"The Value of b: " << b << endl;
cout <<"The Value of c: " << c << endl;
cout << "please type '+' for abstraction, '-' for substraction,
'/' for division, and '*' for multipication"<< endl;
cin >> reply >>;
Too many >>
if (reply= + ) {

Quote the the characters.
 
I

ianenis.tiryaki

Loose this.



main returns int.

Superfluous comment.


Wrong type.



Too many >>

Quote the the characters.

so man how can i identify "reply" if you say int is not the right way?
 
I

Ian Collins

I won't ask you again not to quote signatures, I'll just ignore you.
so man how can i identify "reply" if you say int is not the right way?
Well what type is it? Hint, what do you compare it against (and how are
you comparing)?
 
I

Ian Collins

Tim said:
You're much nicer than I would be with these homework problems.
I think hints rather than answers are acceptable for homework questions.
Direct answers don't to the OP any favours.
 
O

osmium

well i wrote this code but it doesn't work and shows me bunch of
syntax if you can help me out finding them i would appreciate it!

the program should do simple calculations and no parenthesis are
allowed.so it is basically really simple but i am new at programming
and not sure about my code. Thank you!

here is my code:

#include <iostream>
#include <string>
#include <iostream.h>

Choose a form and stick with it. Either <iostream> (preferred) or
using namespace std;

void main()

{
int b, c ; //declearing the variables
int reply;
int output;


cout << "Please enter 2 numbers" << endl;
cin >> b >> c;
cout <<"The Value of b: " << b << endl;
cout <<"The Value of c: " << c << endl;
cout << "please type '+' for abstraction, '-' for substraction,
'/' for division, and '*' for multipication"<< endl;
cin >> reply >>;

if (reply= + ) {

You want the symbol + to be treated as a character constant. *Proper*
character constants are indicated like this:

if(reply = '+') {

This has repercussions elsewhere in your program.

Furthermore you want == which tests for equality, not = which is the
replacement operator in C++.
 
R

red floyd

Tim said:
You're much nicer than I would be with these homework problems.

Actually, he's OK here. He is apparently trying, and posting what he
did do, in accordance with FAQ 5.2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top