Thread: If/else statement not working

  1. #1
    Registered User
    Join Date
    Jan 2006

    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!

    #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";
        cout<< "How many xbox games does John have?\n";
        cout<< "So John has "<< john.gamecube <<" gamecube games, right?\n";
        cout<< "1. Yes\n2. No\n";
        cin>> a;
        if (a = 1){
              cout<< "You're right!";
        else {
             cout<< "You're wrong!";

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    New York
    >> 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, 11:31 AM
  2. multiple conditions - if statement
    By dibble in forum C Programming
    Replies: 8
    Last Post: 03-28-2009, 12:41 PM
  3. crazy if statement
    By jamespond88 in forum C Programming
    Replies: 26
    Last Post: 03-19-2009, 04:02 PM
  4. Max/min function not working correctly
    By En-Motion in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2009, 12:28 AM
  5. Replies: 1
    Last Post: 08-31-2004, 04:07 AM