Thread: if problems

  1. #1
    Unregistered
    Guest

    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.

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    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!)

  3. #3
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    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 compile code with:
    Visual Studio.NET beta2

  4. #4
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    I *just* beat you, Witch_King.

  5. #5
    Anti-Terrorist
    Join Date
    Aug 2001
    Location
    mming, Game DevelopmentCSR >&<>&2Minimization of boolean functions, PROM,PLA design >&0>&WA, USA guitar, dogsCommercial Aviation >&>>&USAProgramming
    Posts
    742
    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!!
    I compile code with:
    Visual Studio.NET beta2

  6. #6
    Unregistered
    Guest
    thanks..umm both you guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM