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

Problem: You are assigned to program a game that simulates a monthly lottery. Ev

ID: 3708859 • Letter: P

Question

Problem: You are assigned to program a game that simulates a monthly lottery. Every month, seven distinct random integers between 1 to 20 (inelusive) are drawn. Using a vector, do the followings: a Generates seven distinct random numbers between 1 and 20 (inclusive) and stores them in a vector. b. Sorts the vector containing the lottery numbers. c. Prompts the player to select seven distinct integers between 1 and 20 and stores the numbers in the vector d. Determines whether the player guessed the lottery numbers correctly. If the player guessed the lottery numbers cormectly,it outputs the right message. 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 numbens. In c++ Submission instructions for option 1: Test your code before submission. You have to use vectors not arrays · dd cmnts to esplain your solution

Explanation / Answer

#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<time.h>

using namespace std;

int main(){
    vector<int> data;
    vector<int> data1;
    srand(time(NULL));
    int a;
    int found;
    string ch;

    while(true){
       int win = 1;
       for (int i = 0; i<7; i++){
           int found = 1;
           while(found == 1){
               found = 0;
               int a = rand()%20 + 1;
               for (int j = 0; j<data.size(); j++){
                  if (data[j] == a){
                     found = 1;
                     break;
                  }
               }
           }
           data.push_back(a);
       }
       sort(data.begin(),data.end());
       cout << "Enter seven numbers between 1 and 20 inclusive:";
       for (int i = 0; i<7; i++){
           int a;
           cin >> a;
           data1.push_back(a);
       }
       for (int i = 0; i<7; i++){
          found = 0;
          for (int j = 0; j<7; j++){
              if (data1[i] == data[j]){
                 found = 1;
                 break;
              }
          }
          if (found == 0){
             win = 0;
             break;     
          }
       }
       if (win == 1)
          cout << "Congratulations! You won!!! ";
       else
          cout << "Sorry!! You lost ";
       cout << "Would you like to play (y/n):";
       cin >> ch;
       if (ch[0] == 'n')
          break;
    }
    return 0;
}

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