If/else statement not working

This is a discussion on If/else statement not working within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm new at programming and I made this little program to test myself... but it didn't work! The problem ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    1

    If/else statement not working

    Hi, I'm new at programming and I made this little program to test myself... but it didn't work! The problem seems to be at the end with the if/else statement. It always says "You're right!". Thanks in advance!

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        int a, b, c;
        struct gamelibrary {
               int gamecube;
               int playstation;
               int xbox;
               };
        gamelibrary john;
        cout<< "How many gamecube games does John have?\n";
        cin>> john.gamecube;
        cout<< "How many playstation games does John have?\n";
        cin>> john.playstation;
        cout<< "How many xbox games does John have?\n";
        cin>> john.xbox;
        cout<< "So John has "<< john.gamecube <<" gamecube games, right?\n";
        cout<< "1. Yes\n2. No\n";
        cin>> a;
        cin.get();
        if (a = 1){
              cout<< "You're right!";
              }
        else {
             cout<< "You're wrong!";
                    }
    
        cin.get();
    }

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> if (a = 1)

    Two equals signs for comparison.

    if(a == 1)
    if(a == john.gamecube)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-07-2009, 12:31 PM
  2. multiple conditions - if statement
    By dibble in forum C Programming
    Replies: 8
    Last Post: 03-28-2009, 01:41 PM
  3. crazy if statement
    By jamespond88 in forum C Programming
    Replies: 26
    Last Post: 03-19-2009, 05:02 PM
  4. Max/min function not working correctly
    By En-Motion in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2009, 01:28 AM
  5. Replies: 1
    Last Post: 08-31-2004, 05:07 AM

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