By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,122 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,122 IT Pros & Developers. It's quick & easy.

Simple integer Expression!

P: n/a
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;

}

Mar 23 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
ia*************@gmail.com wrote:
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.
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;

}

--
Ian Collins.
Mar 23 '07 #2

P: n/a
On Mar 22, 9:22 pm, Ian Collins <ian-n...@hotmail.comwrote:
ianenis.tiry...@gmail.com wrote:
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 ; //declaring 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.
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;
}

--
Ian Collins.
so man how can i identify "reply" if you say int is not the right way?

Mar 23 '07 #3

P: n/a
On Mar 22, 9:22 pm, Ian Collins <ian-n...@hotmail.comwrote:

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

Mar 23 '07 #4

P: n/a
????

Mar 23 '07 #5

P: n/a
ia*************@gmail.com wrote:
On Mar 22, 9:22 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>
>> int reply;

Wrong type.
>> if (reply= + ) {
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)?

--
Ian Collins.
Mar 23 '07 #6

P: n/a
Tim H wrote:
On Mar 22, 9:22 pm, Ian Collins <ian-n...@hotmail.comwrote:

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.

--
Ian Collins.
Mar 23 '07 #7

P: n/a
<ia*************@gmail.comwrote:
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
<iostrream.hif your compiler won't accept the modern form.
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++.

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;

}

Mar 23 '07 #8

P: n/a
Tim H wrote:
On Mar 22, 9:22 pm, Ian Collins <ian-n...@hotmail.comwrote:

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.
Mar 23 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.