I just learned how to program in C++ this last week, and I wrote my first program using Microsoft Visual Studios 2010 express. My computer at home is a Mac and doesn’t have MS Visual studios so I decided to use xcode and copy my code from MS visual studios into xcode. For the most part there aren’t any errors except that xcode has a problem with my boolean logic syntax. Here are a few of the examples from my code that it has a problem with:
if(place == 1)
{
cout<< name << " 'IS NOW THE FASTEST JUNIOR IN THE UNITED STATES!!!\n";
cout<< "ABSOLUTLY INCREDIBLE!!!!! WHAT AN AMAZING RACE\n"
<< endl
<< endl;
cout<< "You did it! You won the race and are now the fastest Junior skier in the USA!\n";
cout<< "All that hard work really paid off for you!\n";
<<endl;
}
else (place >1)
{
cout << "You skied a great race, but unfortunately you did not beat Ben.\n";
cout<< "You can always race again next year and shoot for gold.\n"
<<endl;
}
The error that comes up says “Expression result unused.” How do I fix this?
If we start with the first line of your code snippet (which was much easier to read and understand after formatting it properly):
This is the last part of an
ifstatement, and means that if the condition in theifwas not true, then do the statement afterelse. In your case it’s an expression that checks ifplaceis larger than one then throw away the result, so it does nothing really. You probably mean to useelse ifinstead of onlyelse.Then look at the next line:
Here you do the same mistake again, but now with an
elsewhere none are supposed to be, which is an error in itself. You probably meanelse ifhere too.