Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE HELP.... I JUST DID 16 Problems and this one has me completly baffled. I

ID: 3632661 • Letter: P

Question

PLEASE HELP.... I JUST DID 16 Problems and this one has me completly baffled.
I have tried 7 times and failed 7 times when the program failed to compile.
Write a program that does the following:
A. Generates five distinct random numbers between 1 and 40 (inclusive) and stores them in an array.
B. Sorts the aray containing the lottery numbers.
C. Prompts the player to select five distinct integers between 1 and 40 (inclusive) 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 stored.
D. Determines whether the player guessed the lottery numbers correctly. If the player guessed the lottery numbers correctly, it outputs the message "You Won" in not the message outputs " You LOSE" and outputs the lottery numbers. Make sure the program allows the players to play as many times as they want to.

Explanation / Answer

#include <iostream>

#include <time.h>

using namespace std;

#define SIZE 5

void sort(int[],int);

int _tmain(int argc, _TCHAR* argv[])

{

char choise = 'y';

do{

srand(time(NULL));

int arra[SIZE];

for(int i = 0; i < SIZE; i++)

{

arra[i] = ((rand() % 40) +1);

for(int j = i-1; j >= 0 ;j--)

if(arra[i] == arra[j])

{

i--;

break;

}

}

sort(arra, SIZE);

int userInput[SIZE];

cout<<"Enter "<<SIZE<<" distinct number: ";

for(int i=0;i<SIZE;i++)

cin >> userInput[i];

bool won = true;

for(int i = 0; i<SIZE; i++)

if(arra[i] != userInput[i])

{

won = false;

break;

}

if(won)

cout<<" You Won ";

else

cout<<" You LOSE ";

cout<<"Lottery number are: ";

for(int i=0;i<SIZE;i++)

cout<<arra[i]<<" ";

cout<<" Do you want to play again (y-yes, n-no): ";

cin >> choise;

}while(choise != 'n' && choise != 'N');

return 0;

}

void sort(int a[], int size)

{

for(int i = 0; i < size-1; i++)

for(int j = i+1; j < size; j++)

if(a[i] > a[j])

{

int tmp = a[i];

a[i] = a[j];

a[j] = tmp;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote