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

Probleml: You have four identical prizes to give away and a pool of 25 finalists

ID: 3870184 • Letter: P

Question

Probleml: You have four identical prizes to give away and a pool of 25 finalists. The finalists are assigned numbers from 1 to 25. Write a program to randomly select the numbers of 4 finalists to receive a prize. Make sure not to pick the same number twice. For example, picking finalists 3, 15, 22, and 14 would be valid but picking 3, 3, 31, and 17 would be invalid, because finalist number 3 is listed twice and 31 is not a valid finalist number. Print the numbers of the four finalists. At the beginning, ask the user to enter an integer which you pass in to the srand.) function. Do not use srandtime(NULL) as this will generate random output which will not pass the test cases. See the posted template on ZyBooks. cout

Explanation / Answer

#include<iostream>

#include<stdlib.h>

#include<time.h>

using namespace std;

void validRandomNumber(int r){

srand(r);

int a[r];

cout<<"Four Finalists are : "<<endl;

for(int i=0;i<r;i++){

a[i] = 1+rand()%25;

cout<<a[i]<<" ";

}

}

using namespace std;

int main(){

cout<<"Enter integer for srand :";

int randomNum =0;

cin>>randomNum;

validRandomNumber(randomNum);

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