while input != 0
{
if input == "r";
cout << "Please input a floating point value for the height, and then a floating point value for the width, seperated by a comma.开发者_C百科" << endl;
cin >> height >> width;
}
I am trying to write a basic program that takes the dimensions of basic shapes and outputs the area. This is what I am starting with, but I am not sure what is wrong with this syntax. Could someone help?
The condition must be in parentheses. Here's your formatted code:
while (input != 0)
{
if (input == "r")
{
cout << "Please input a floating point value for the height, and then a floating point value for the width, seperated by a comma." << endl;
cin >> height >> width;
}
}
You need to have your conditions surrounded by brackets and if needs to have code to execute if the condition is true its not a function call, so :
while (input != 0)
{
if (input == "r"){
cout << "Please input a floating point value for the height, and then a floating point value for the width, seperated by a comma." << endl;
cin >> height >> width;
}
}
It also looks like your cin statement is wrong as well but without the rest of the code I don't know.
C++ parser/compiler isn't intelligent enough yet to understand what do you mean when you try to say
if input == "r"
when input != 0
compiler will get confused and won't be able to semantically understand your program. So you need to put parenthesis as mentioned in above answers.
精彩评论