if problems

This is a discussion on if problems within the C++ Programming forums, part of the General Programming Boards category; sorry but i'm stuck again...heres my code #include <iostream> #include <string> using namespace std; int main() { string name; cout<<"Enter ...

  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!)
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  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.
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  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, 05:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 04:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 03:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21