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

C reat a number drawing program in C++ For those of you that do not know how the

ID: 3851266 • Letter: C

Question

Creat a number drawing program in C++
For those of you that do not know how the game is played, each game is played by drawing 5 numbers and a power ball number. The numbers drawn are between 0 and 60. Once a number is drawn, the next number cannot be that number and so forth. For instance, if you draw number 48, the next number will be between 0 and 60, but not 48. This is the rule for the first 5 numbers in the drawing. Finally, the Powerball is drawn. This number is between 1 and 35 and CAN be any of the numbers already drawn already. This bag of numbers for the Powerball is completely separate from the other numbers. So if you draw number 15 for the 2nd number and the Powerball drawn is 15, it is perfectly legal.

Basically, when you run your program, your program will randomly pick 5 numbers that are non-repeating and can range between 0 and 60. However, the numbers cannot equal 0 or 60. So all in all, the range of numbers is 1 – 59. Once your program selects those numbers and checks them against themselves, it will then draw a random Powerball number, that is in a range from 1 to 35. It will then display the numbers to the user running the program.

PLEASE NOTE, be sure that you run the program several times to make sure you are randomizing the numbers each time you run the program. There is a chance that you could run the program several times and get the same number. You must randomize each draw of the numbers.

Explanation / Answer

#include<iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;


int main(){

int num_array[5], power_ball,i,j;

srand(time(NULL));
for(i=0;i<5;i++){


num_array[i]=(rand()%58)+1; // to generate number between 0 and 60
j=0;

// to check for repeating numbers
while(j<i){
if(num_array[j]==num_array[i]){
i--;
break;
}
j++;
}

}

//to draw power ball number
  
power_ball=rand()%35+1;


//display random numbers

for(i=0;i<5;i++)
cout<<num_array[i]<<" ";

//display power ball number

cout<<" Power Ball "<<power_ball<<endl;


}