Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!image text in transcribed

#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;

}

ITY OF PASSAIC LOTTO MODEL: ) PLAY LOTTO QUIT PROGRAM lease make a selection: 1 lease enter your name: ana rojas lease enter_number 1: 23 Please enter number 2: 45 The number must be between 1 and 40. Please enter number 3: 30 Please enter number 4: 21 Please enter number 5: 171 Please enter number 6: 10 Please enter number 7: 25 ana rojas LOTTO RESULTS WINNING TICKET NUMBERS: 3 12 24 364 10 35 ana rojas TICKET: 23 45 30 21 17 18 25 RESULTS: NUMBER MATCHES: 1 WINNINGS: SORRY. NADA. ZILCH. ZERO. TRY AGAIN NEXT TIME ! CITY OF PASSAIC LTTO MODEL: 1) PLAY LOTTO 2) QUIT PROGRAM Please make a selection<>

<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago