Hello all,
I am trying to make a lottery number generator. So I need 6 random numbers.
The current code below displays the same number 6 times. Thoughts?
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
char userchoice;
int main()
{
cout<<"Welcome to The Lottery Wizard!"<<endl<<endl;
cout<<"This program will allow you to play the lottery from"<<endl;
cout<<"the comfort of your computer desk."<<endl<<endl;
cout << "Do you want to play the Lottery? (y = yes, n = no): ";
cin.sync();
cin.get(userchoice);
userchoice = tolower(userchoice); //convert user's answer to lowercase
while (userchoice != 'y' && userchoice != 'n')
{
cout << "Invalid response. Enter a y for yes or n for no: ";
cin.sync(); // clear out buffer
cin.clear(); // set read to good
cin.get(userchoice);
}
system("cls");
while (tolower(userchoice) == 'y')
{
cout<<"The six random lottery numbers are:";
int number_back;
srand( time (NULL) ); //gets seed from clock
number_back = rand() % 53 + 1; //formula for 1-53 random number
for (int count = 0; count < 6 ; count++)
cout<<number_back<<endl;
cout << "Do you want to play the Lottery? (y = yes, n = no): ";
cin.sync();
cin.get(userchoice);
userchoice = tolower(userchoice); //convert user's answer to lowercase
while (userchoice != 'y' && userchoice != 'n')
{
cout << "Invalid response. Enter a y for yes or n for no: ";
cin.sync(); // clear out buffer
cin.clear(); // set read to good
cin.get(userchoice);
}
}
system("cls");
cout<<"Thanks for playing"<<endl<<endl;
return 0;
}