Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your state is in a process of creating a weekly lottery. Once a week, five distinct random integers between 1 to 40 (inclusive) are drawn.

Your state is in a process of creating a weekly lottery. Once a week, five distinct random integers between 1 to 40 (inclusive) are drawn. If a player guesses all of the numbers correctly, the player wins a certain amount. Write a program that does the following:

Step a: Generates five distinct random numbers between 1 and 40 (inclusive) and stores them in an array.

Step b: Sorts the array containing the lottery numbers.

Step c: Prompts the player to select five distinct integers between 1 and 40 (inclu- sive) and stores the numbers in an array. The player can select the numbers in any order, and the array containing the numbers need not be sorted.

Step d: Determines whether the player guessed the lottery numbers correctly. If the player guessed the lottery numbers correctly, it outputs the message You win!; otherwise it outputs the message You lose! and outputs the lottery numbers.

Your program should allow a player to play the game as many times as the player wants to play. Before each play, generate a new set of lottery numbers.

//-----------main----------

#include #include #include #include #include "functions.cpp"

using namespace std;

int main() { int lottoNum[ARRAY_SIZE]; int custNum[ARRAY_SIZE];

char resp;

cout << "Play lotto (Y/y)/(N/n): "; cin >> resp; cout << endl;

while (resp == 'y' || resp == 'Y') { initializeList(lottoNum); getLottoNum(lottoNum); sortLottoNum(lottoNum); getCustNum(custNum); // part d // using checkLottoNum, determine if the player has guessed correctly checkLottoNum(lottoNum, custNum);

cout << "Play another (Y/y)/(N/n): "; cin >> resp; cout << endl; }

return 0; }

//--------end of main--------

//--------functions.cpp (well what I have so far)-----------------

#include #include #include #include

using namespace std;

const int ARRAY_SIZE = 5;

inline void initializeList(int list[]) { for (int index = 0; index < ARRAY_SIZE; index++) list[index] = -1; }

inline bool numInList(int list[], int num) { for (int index = 0; index < 5; index++) if (list[index] == num) return true; return false; }

// part a inline void getLottoNum(int list[]) { //srand(time((0)); //for (int i = 0) // set the items in "list" to random numbers between 1 and 40, inclusive int i; //while (decide == 'Y' || decide == 'y') srand(time(0)); cout << "Generated lottery numbers: "; for (i=0; i

for (i=0; i

// part b inline void sortLottoNum(int list[]) { int temp; int iteration; int index; for (iteration = 1; iteration < ARRAY_SIZE; iteration ++) { for (index = 0; index < ARRAY_SIZE; index++) if(list[index] > list[index+1]) { temp = list[index]; list[index] = list[index+1]; list[index+1] = temp; } }

inline void getCustNum(int list[]) { int inNum; // prompts the player to select 5 distinct numbers between 1 and 40, inclusive cout << "Enter 5 distinct numbers between 1 and 40 inclusive" << endl; // ensure that the numbers are between 1 and 40, inclusive for(int index= 0; index < ARRAY_SIZE; index++) { cin >> inNum; if (inNum < 1 || inNum > 40) cout << "Error: you must enter a number between 1 and 40" << endl; cout <<"Try Again" << endl; return; // store the numbers in "list" cin >> list[index]; } }

// part d inline bool checkLottoNum(int list1[], int list2[]) { sortLottoNum(list2); for(int index = 0; index = ARRAY_SIZE; index++) { if (list1[index] != list2[index]) cout << "You Lose" << endl; return false; } cout << "You Win" << endl; return true; // determine if the user has guessed all 5 numbers correctly }

inline void printList(int list[]) { for (int i = 0; i < ARRAY_SIZE; i++) cout << list[i] << " "; cout << endl; }

//------end of functions.cpp ------------

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions