473,385 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Simple integer Expression!

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
8 1537
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
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
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
????

Mar 23 '07 #5
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
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
<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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: j.mandala | last post by:
I created a simple link between two tables in a query. TableA has Social Security numbers stored as Long Integer Data. (I imported this table). The Join is between these two fields Table ...
5
by: Yodai | last post by:
Hi all! I have an int that comes with a value like 0x07fa and I have to turn it into a float value of 204.2 decimal to display it.... if I try to divide it by 10 I get bogus numbers. I presume...
4
by: Ray | last post by:
When a single-bit bitfield that was formed from an enum is promoted/cast into an integer, does ANSI C say anything about whether that integer should be signed or unsigned? SGI IRIX cc thinks it is...
20
by: Brian Tkatch | last post by:
An ORDER BY a simple-integer inside a FUNCTION, results in SQL0440N, unless the FUNCTION expects an INTEGER as its parameter. For example: DECLARE GLOBAL TEMPORARY TABLE A(A CHAR(1)) INSERT INTO...
6
by: sarathy | last post by:
Hi, What is integer promotion? How is it different from arithmetic conversion? Regards, Sarathy
34
by: Cuthbert | last post by:
Hi folks, I am trying to find a more efficient way to count "How many bits are '1' in a integer variable?". I still have no idea to count the bits except using a loop and "if" statements....
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
5
by: wazzup | last post by:
My task is Create a program to read a simple integer expression and display the result. "Simple" means no parentheses are allowed and only the +, -, *, and / operators are allowed. I think...
17
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code:...
55
by: copx | last post by:
Can anyone point me to a simple, fast RRNG function to generate random ints within a specified range? It is important that each value within the range has the same probability (uniform...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.