Hey there. I'm doing some homework, and my teacher has asked us to create a .cpp program in Visual Studio 2010. I created my program and started out with 19 errors. I brought it down to 4 and I can not figure out what I've done wrong. They're all in Line 40, one of them being Error c2143 syntax error: missing ; befor <<. The other three are expected an expression. I've done everything I can think of, and I've looked it up online and in my book. I'm a beginner, so I know it must be something simple, but would appreciate the help. Thanks! My code is typed below. (Highlighting the line that it says all of my errors are in).
#include <iostream>
using namespace std;
int main ()
//enter input items
cout << "Enter the price of the first item: ";
cin >> firstNum;
cout << "Enter the price of the second item: ";
cin >> secondNum
// determine whether the data is valid
;if (firstNum<secondNum)
{
//caluclate and siplay the output
double temp =0;
temp = firstNum;
firstNum = secondNum;
secondNum = temp;
} //end if
//calculate the total price with BoGoHo
halfSecondNum = secondNum / 2;
total = halfSecondNum + firstNum
//display the output item ;cout ;<< "Total price: $" ;<< total ;<< endl;
system ("pause")
;return 0;
//end of main function
}
First off, welcome to the forums. Secondly, when posting code, please remember to use the [code][/code] tags surrounding you code to preserve the indentation and to enable easily read code.
Moving on to your issue. I see what you did, you added a bunch of semicolons because the compiler said they were expected. It is simple because you forget the semicolon on the line before. Here: total = halfSecondNum + firstNum
And then remove all of the semicolons from this line except the one at the end: ;cout ;<< "Total price: $" ;<< total ;<< endl;