I am trying to write a program that generates a table of temperature conversions. I am very new to C++ and I really need some help. I do know that there is error in my code and it will not compile. I haven't learned how to read the errors (and google hasn't helped) that command prompt alerts you to when compiling fails. So as you can imagine it's very hard to correct my errors, and I'm not even sure the code I have used will properly generate a table. Please help!
Errors displayed by command prompt:
other.cpp: In function" int main<>':
other.cpp:34:10:error: expected primary-expression before '=' token
Oh I should have started with 1 since I am trying to generate a table from 1 to 50 USD (and the second column the conversion in peso, third column rand, and forth yen) in increments of 1 USD. So here's my new code, but it still won't compile and gives me the same errors :
Do you see how every other for loop is structured?
Like this:
for (initialization; condition; increase) { statements... };
The first part of that loop, initialization, is to define or initialize a variable. So instead of
1 2 3 4
for( = 1.0; YEN <= 50.0; YEN += 1.0)
{
cout << setw(10) << USD*PESO << setw(10) << USD*RAND << setw(10) << USD* YEN << endl;
}
You would need to put a variable on the left side of the = 1.0, such as YEN or PESO or USD or even int i = 1.0, or you can leave it blank, either way, you cannot just have = 1.0;
Try:
1 2 3 4
for(YEN = 1.0; YEN <= 50.0; YEN += 1.0)
{
cout << setw(10) << USD*PESO << setw(10) << USD*RAND << setw(10) << USD* YEN << endl;
}
Thank you soo much! It works! Just one last question I have the table set to end on row 50 however when I run the program it displays the 1-50 rows I want and a bunch of rows with 51 USD and the end, why is this happening? Thanks again!
You're using your curency variables (USD,PESO,RAND,YEN) as both loop indexes and a currency value. Using them as a loop index changes their value. When you drop out of the first for loop, USD has a value of 51, not a value of 1 as you had initially assigned.
If you had declared your currency variables as const values, your compiler would have detected your improper attempts to change them: