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

Thank you for giving this a try. My prof would like this answered using the sran

ID: 3633608 • Letter: T

Question

Thank you for giving this a try. My prof would like this answered using the srand() function. He also provided a correct syntax that he wants us to include in the code. Here it is : srand( static_cast<unsigned>( time( NULL ) ) ); My compiler is XCode. Here is the problem:

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:

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

b. Sorts the array 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 sorted.

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.

Thank you for your time!

Explanation / Answer

please rate - thanks

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;  
bool NoDuplicates(int[],int,int);
void getWinningNumbers(int[]);
void getPlayersNumbers(int[]);
void sort(int[]);
bool compare(int[],int[]);
void print(int[]);
int main()
{srand( static_cast<unsigned>( time( NULL ) ) );
int lotto[5],player[5];
char yes;
do   
   {getWinningNumbers(lotto);
    sort(lotto);
    //print(lotto);   //- for testing
    getPlayersNumbers(player);
    if (compare(lotto, player))
        cout<<"You win!"<<endl;
    else
        {cout<<"You lose!"<<endl;
         cout<<"The numbers are: ";
         print(lotto);
        }
        cout<<"Play again(Y/N): ";
        cin>>yes;
      }while(toupper(yes)=='Y');
return 0;
}

void getWinningNumbers(int a[])
{int i;
bool dup=true;
for(i=0;i<5;i++)
   {while(dup)
     {a[i]=rand()%40+1;
      dup=NoDuplicates(a,i,2);
      }
     dup=true;
   }
}
bool NoDuplicates(int a[],int n, int f)
{int i,j;
bool dup=false;
if(n==0)
     return false;
for(i=0;i<=n-1;i++)
     if(a[n]==a[i])
        {dup=true;
           if(f==1)        //from getPlayersNumbers
           {cout<<"DUPLICATE PICK numbers you've already chosen are:";
            for(j=0;j<n;j++)
                cout<<a[j]<<" ";
            cout<<endl;
            }
        }
return dup;
}
void getPlayersNumbers(int a[])
{int i;
bool dup=true;
for(i=0;i<5;i++)
   {dup=true;
    while(dup)
     {cout<<"Enter number (between 1 and 40) "<<i+1<<": ";
      cin>>a[i];
      if(a[i]<1||a[i]>40)
          cout<<"number out of range ";
      else
         dup=NoDuplicates(a,i,1);
      }
   }
}


void sort(int a[])
{int i,j,t;
for(i=0;i<4;i++)
    for(j=i;j<5;j++)
       if(a[i]>a[j])
           {t=a[i];
           a[i]=a[j];
           a[j]=t;
           }
   
}
bool compare(int a[],int b[])
{int i,j,same=0;
   for(i=0;i<5;i++)
      for(j=i;j<5;j++)
          if(a[i]==b[j])
             same++;
if(same==5)
     return true;
return false;
}      
void print(int a[])
{int i;
for(i=0;i<5;i++)
    cout<<a[i]<<" ";
cout<<endl;
}

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