So, no matter what i do, i can't seem to be able to fix this error, could someone please help me?
[code]
#include <iostream>
using namespace std;
string input1;
string input2;
int main()
{
cout<< "Hello World, My Name is Jeffery."<<endl;
cout<< "What is Your Name?"<<endl;
cin>> input1;
cout<< "Nice to Meet You, "<< input1 << "!"<<endl;
cout<< "Would You Like To Play A Game "<< input1 <<"?"<<endl;
cin >> input2;
if (input2 == "Yes" || "yes");
{
cout << "Alright, let's play a story building game"<< endl;
}
else (input2 == "no" || "No");
{
exit(0);
}
}
Thank You so much for all the help, I really appreciate it!
1. Don't put semi-colons after if or else statements.
2. else statements have no condition. This follows logically, because it's like saying "otherwise... do this".
3. Each logical comparison must stand on its own.
1 2 3 4
if (input2 == "Yes" || input =="yes")
{
}
1 2 3 4
else
{
}
Also, the exit(0) is unnecessary, which extends to saying your entire else statement is pointless.
As a side note, input2 == "no" || "No" doesn't do what you think it does. You need to write: input2 == "no" || input2 == "No". You could also simply make that something like: some_tolower_function(input2) == "no"
FYI:
c++ does not care about whitespace in the code.
c++ does not have an elif or elseif type statement.
put those 2 together, and understand that a lot of code has
if (blah)
else if (other)
else
looking blocks, but the else and the if are really 2 statements on a single line.
its really just a condensed version of chained condition statements.
exit zero is heavily frowned upon, or used to be. It does not clean up the program well. You should use return(0) in main instead, or terminate() if you really, really need to self-destruct the program somewhere. Its not for ending the program normally, its for critical failures ... if you need to end the program, provide a normal path to do that (hitting a return statement in main is the normal path). You may have multiple return statements in main (and any other function as well).
Hello! Else is not followed by conditions! Its not else (...condition...) do smth, its only else do smth! Secondly, dont put semicollons "{}" after each if or else statement if you only have one action. Add semicollons when you want your if statement to do more than one action. Also, instead of exit(0), add return 0. Hope I helped! Good luck.