0

Hi, I'm new to C++, and I made this program that makes either 1, or 2 pop up. And for 1, a text field is suppost to pop up to show you won, and if 2 pops up, it's suppost to say you lose. I got everything down (The unmber generator and stuff) But I'm having trouble with the IF and ELSE statement... The IF statement works fine, but my ELSE statement doesn't show up.... Here is the code....

#include <cstdlib> 
#include <ctime> 
#include <iostream>

using namespace std;

int main() 
{ 
     system("CLS");
     cin.clear();
     
 
    srand((unsigned)time(0)); 
    int random_integer; 
    for(int index=0; index<1; index++){ 
        random_integer = (rand()%2)+1; 
        cout << random_integer << endl; 
        if(index=1)
        {
        cout << "You won!" << endl << endl;
        }else{      
              cout << "You lose...."<< endl << endl;
        }
        system("PAUSE");
        return 0;
    } 
}

Please if anyone can point out what is wrong, please tell me, thx :D

2
Contributors
4
Replies
6
Views
9 Years
Discussion Span
Last Post by DealthRune
0

Now only the ELSE statement is coming up... It shows the number and says "You Lose...." for both numbers....????

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.