Help in C++

A

Allan

Ok, I got some good advise. I re-wrote the program and now I'm down to only
1 error. Below is my code and my error. Any ideas what it is?
#include <iostream>

using std::cout;
using std::cin;
using std::endl;


// Function main begins program execution

int main()

{

int tempinfah; //temp in Fahrenheit
int tempincel; //temp in Celsius

cout<<"enter temperature in Fahrenheit\n";//Prompting for user input
cin>>tempinfah; //user input

tempincel = (tempinfah-32)*(5/9)

cout<<"Temperature in Celsius" << endl;

return 0;


}
error: C:\Program Files\Microsoft Visual Studio\MyProjects\Assignment
11\11.cpp(24) : error C2146: syntax error : missing ';' before identifier
'cout'
Error executing cl.exe.

Assignment 11.exe - 1 error(s), 0 warning(s)
 
M

Mike Wahler

Allan said:
Ok, I got some good advise. I re-wrote the program and now I'm down to only
1 error. Below is my code and my error. Any ideas what it is?
#include <iostream>

using std::cout;
using std::cin;
using std::endl;


// Function main begins program execution

int main()

{

int tempinfah; //temp in Fahrenheit
int tempincel; //temp in Celsius

cout<<"enter temperature in Fahrenheit\n";//Prompting for user input
cin>>tempinfah; //user input

tempincel = (tempinfah-32)*(5/9)

Exactly what the message says, you're missing a semicolon
here, which is just before 'cout' below.
cout<<"Temperature in Celsius" << endl;

return 0;

Also note that you're still truncating your results
as others have already pointed out.
}
error: C:\Program Files\Microsoft Visual Studio\MyProjects\Assignment
11\11.cpp(24) : error C2146: syntax error : missing ';' before identifier
'cout'
Error executing cl.exe.

Assignment 11.exe - 1 error(s), 0 warning(s)

-Mike
 
J

Jacek Dziedzic

Allan said:
Ok, I got some good advise. I re-wrote the program and now
I'm down to only 1 error. Below is my code and my error.
Any ideas what it is?
[...]
error C2146: syntax error : missing ';' before identifier
'cout'

Well, the compiler told you, plain and simple. You're
missing a semicolon before 'cout', or in other words after

tempincel = (tempinfah-32)*(5/9)

If you fix it your program will compile, but it won't work
as expected as you have two more errors left.

One is that (5/9) evaluates to zero, because your variables
are integer (ints) and hence cannot represent 5/9.

The other is that you neglect to output your calculated
result. Duh!

HTH,
- J.

PS. Get a textbook!
 
G

Gianni Mariani

Allan said:
Ok, I got some good advise. I re-wrote the program and now I'm down to only
1 error. Below is my code and my error. Any ideas what it is?
#include <iostream>

using std::cout;
using std::cin;
using std::endl;


// Function main begins program execution

int main()

{

int tempinfah; //temp in Fahrenheit
int tempincel; //temp in Celsius

cout<<"enter temperature in Fahrenheit\n";//Prompting for user input
cin>>tempinfah; //user input

tempincel = (tempinfah-32)*(5/9)

cout<<"Temperature in Celsius" << endl;

return 0;


}
error: C:\Program Files\Microsoft Visual Studio\MyProjects\Assignment
11\11.cpp(24) : error C2146: syntax error : missing ';' before identifier
'cout'
Error executing cl.exe.

Assignment 11.exe - 1 error(s), 0 warning(s)


Cool, like the other posters said, you'll need that ';' after the
"tempincel = (tempinfah-32)*(5/9)".

In C++, every statement is followed by a ';'. Not to be confused with
statements grouped by "{" and "}" which is a compound statement.

The next problem is the "int", you have 2 alternatives in C and C++,
"float" and "double". So, instead of using "int" for temperatures, use
double. But you still have a problem because "5" and "9" are integers
and (5/9) will still be zero - but (5.0/9.0) is a double (in fact, so is
(5/9.), (5./9), (5e0/9), (5*1./9) - you'll need to study type promotion
to get this, suffice to say (5.0/9.0) is easy and unambiguius to read so
it's the best choice.

Last thing.

You'll need to place "<< tempincel" somewhere interesting.

If you have any other issues, go ahead an respond with a copy of what
you've got after you make the changes. It's cake !
 
A

Allan

How do I output my calculated result? Like I said earlier, I got a late
start in this class, and I do have a textbook.
This assignment is due tomorrow night and I'm beating my head against the
wall trying to catch up. This is just one of three programs I have to write.
Jacek Dziedzic said:
Allan said:
Ok, I got some good advise. I re-wrote the program and now
I'm down to only 1 error. Below is my code and my error.
Any ideas what it is?
[...]
error C2146: syntax error : missing ';' before identifier
'cout'

Well, the compiler told you, plain and simple. You're
missing a semicolon before 'cout', or in other words after

tempincel = (tempinfah-32)*(5/9)

If you fix it your program will compile, but it won't work
as expected as you have two more errors left.

One is that (5/9) evaluates to zero, because your variables
are integer (ints) and hence cannot represent 5/9.

The other is that you neglect to output your calculated
result. Duh!

HTH,
- J.

PS. Get a textbook!
 
K

Kevin Goodsell

Allan said:
How do I output my calculated result? Like I said earlier, I got a late
start in this class, and I do have a textbook.
This assignment is due tomorrow night and I'm beating my head against the
wall trying to catch up. This is just one of three programs I have to write.

Please don't top-post. Read section 5 of the FAQ for posting guidelines.

http://www.parashift.com/c++-faq-lite/

Generally, you can output things like this:

cout << a;

If you want to output multiple things, you can do this:

cout << a << b << c;

If you want some space between the things you output, do this:

cout << a << ' ' << b << ' ' << c;

Or maybe this:

cout << a << ", " << b << ", " << c;

It's a good idea to terminate all output lines with a newline. One way
to do this is with 'endl', but be aware that it also flushes the output
stream, which means if forces buffered output to go to it's final
destination. Generally this may be expensive, which is why buffering is
used. In practice, it will make no difference in the kind of programs
you will write for your class.

cout << a << ", " << b << ", " << c << endl;

-Kevin
 
J

jeffc

Allan said:
Ok, I got some good advise. I re-wrote the program and now I'm down to only
1 error. Below is my code and my error. Any ideas what it is?
#include <iostream>

using std::cout;
using std::cin;
using std::endl;


// Function main begins program execution

int main()

{

int tempinfah; //temp in Fahrenheit
int tempincel; //temp in Celsius

cout<<"enter temperature in Fahrenheit\n";//Prompting for user input
cin>>tempinfah; //user input

tempincel = (tempinfah-32)*(5/9)

cout<<"Temperature in Celsius" << endl;

return 0;
}
error: C:\Program Files\Microsoft Visual Studio\MyProjects\Assignment
11\11.cpp(24) : error C2146: syntax error : missing ';' before identifier
'cout'

I'm going to go way out on a limb here and say that there's a missing ';'
before cout.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top