Lottery code won't stop!


#include<iostream>
#include<string>
#include<ctime>
using namespace std;


int main()
{
int num;

srand(time(NULL));
num = rand() % 7 + 1;

int pick1; int pick2; int pick3;

int win = 0;

{
cout << "It's lottery time!\n";

do{

cout << "Choose a number between 1 and 7\n" << num;

cin >> pick1;
{
if (pick1 == num)
win + 1;

cout << "You got it! You win the prize!\n";

if (pick1 > num)
cout << "That number is too big. Try again!\n";
if (pick1 < num)
cout << "That number is too small. Try again!\n";
}

cout << "Second pick\n";

cin >> pick2;
{
if (pick2 == num)
win + 1;
cout << "You got it! You win the prize!\n";
system("pause");

if (pick2 > num)
cout << "That number is too big. Try one more time!\n";
if (pick2 < num)
cout << "That number is too small. Try one more time!\n";
}
cout << "Final pick\n";

cin >> pick3;
{
if (pick3 == num)
win + 1;

cout << "You got it! You win the prize!\n";

if (pick3 > num)
win + 1;
cout << "That number is too big. Sorry. You lose.\n";

if (pick3 < num)
win + 1;
cout << "That number is too small. Sorry. You lose.\n";
}

}

while (win = 0);
system("pause");

}



}




Sorry if I couldn't convert the code to code text.

I've got this lottery thing that won't stop if the right number is picked. If the right number is picked, I want it to stop, but if the 1st try is right, it moves on to the 2nd try, and if the 2nd try is right, it moves onto the third. Is there something wrong with my while loop?

Please modify the code so it will work and explain why it will work.

Thank you!
Highlight your code and on the right hand side you should see
Format:
tab. The first option is source code. Click that with your code highlighted and it should convert it into something read-able.

P.S. The first obvious sign your do{}while loop is broken is in the while statement you have while(win = 0); this should be while(win == 0);

= is an assignment
== is a comparison
Last edited on
Topic archived. No new replies allowed.