-
if problems
sorry but i'm stuck again...heres my code
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"Enter Your Name: ";
cin>> name;
if(name==Chris)
{
cout<<"welcome Chris";
}
else if(name==nick)
{
cout<<"welcome Nick";
}
return 0;
}
this isn't really what my programs gunna be i was just seeing if i could use the if statements...anyway. could someone tell me whats wrong i have like 4 errors with it.
-
You forgot to put quotes around the names. This is what it should look like...
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"Enter Your Name: ";
cin>> name;
if(name=="Chris")//Here are the missing quotes around Chris
{
cout<<"welcome Chris";
}
else if(name=="Nick") //Here are the missing quotes around Nick
{
cout<<"welcome Nick";
}
return 0;
}
-Chris (that's my name too!)
-
Put quotes around the if statment string literal, example "Chris". Also you don't need the 'if' part following the 'else' as in 'else if', but this is not an error, it is just redundant. If you where making 3 tests than 'else if' would be needed.
-
I *just* beat you, Witch_King.
-
Don't worry. I think I beat you. So I just sent the webmaster an email asking them to reverse the order of posts on this thread!!
-
thanks..umm both you guys