Question
So below is my completed code and when I run it in Visual Studio it's all good. But I'm having trouble with what's starred ***.
So below is my completed code and when I run it in Visual Studio it's all good. But I'm having trouble with what's starred ***. As in if they input a number less than or greater than 40 it still keeps on counting. Also, to if they enter a letter it keeps on infinite loop. Any ideas? thank you!
#include
#include
#include
#include
using namespace std;
int DisplayMenu();
int getLottoPicks(int[], int);
void GenWinNums(int[], int);
void results(int[], int[], int, int, string);
bool NoDuplicates(int[], int, int);
int checkWins(int[], int[], int);
int main()
{
const int NUM = 7;
int UserTicket[NUM], WinningNum[NUM];
string name;
int match = 0;
int choice = 0;
choice = DisplayMenu();
while (choice != '2')
{
if (choice == '1')
{
cout
getline(cin, name);
cout
getLottoPicks(UserTicket, NUM);
GenWinNums(WinningNum, NUM);
match = checkWins(UserTicket, WinningNum, NUM);
results(UserTicket, WinningNum, NUM, match, name);
}
else
cout
choice = DisplayMenu();
}
cout
system("pause");
return 0;
}
int DisplayMenu()
{
bool legal = false;
int choice, enter;
cout
cout
cout
cout
cout
while (!legal)
{
choice = cin.get();
enter = cin.get();
if (choice == '1' || choice == '2')
{
return choice;
}
else
return choice;
}
}
int getLottoPicks(int a[], int n)
{
bool dup = true;
for (int i = 0; i
{
while (dup)
{
cout
cin >> a[i];
if (a[i] 40)
{
// still counts the number that's out of range******************************
cout
}
// if a char is inputed then it goes to an infinite loop**************************
dup = NoDuplicates(a, i, 1);
}
dup = true;
}
return 0;
}
void GenWinNums(int a[], int n)
{
srand((unsigned int)time(NULL));
bool dup = true;
for (int i = 0; i
{
while (dup)
{
a[i] = rand() % 40 + 1;
dup = NoDuplicates(a, i, 2);
}
dup = true;
}
}
//trial & error
bool NoDuplicates(int a[], int n, int s)
{
bool dup = false;
if (n == 0)
return false;
for (int i = 0; i
if (a[n] == a[i])
{
dup = true;
if (s == 1)
{
cout
}
}
return dup;
}
//revealing the user results was pretty fun to do.
void results(int a[], int b[], int n, int k, string name)
{
cout
cout
cout
for (int i = 0; i
cout
cout
for (int i = 0; i
cout
cout
cout
cout
cout
if (k == 7)
cout
else if (k == 6)
cout
else if (k == 5)
cout
else if (k == 4)
cout
else if (k == 3)
cout
else
cout
cout
int enter = cin.get();
return;
}
//so-so
int checkWins(int a[], int b[], int n)
{
int same = 0;
for (int i = 0; i for (int j = 0; j if (a[i] == b[j]) { same++; } return same; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started