Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question bout C++, above is the question from my textbook: My code has no syntax error but when I run it, it output nothing as

image text in transcribed

Question bout C++, above is the question from my textbook:

My code has no syntax error but when I run it, it output nothing as below:

image text in transcribed

Below is my code:

//13.It's in the main function already //pre-condition: 25 different number from 1-25 //post-condition: 4 different random number picked from the above prize(25);

void prize(int candidate) { int a, b, c, d; srand(100); while (int i = 1) { a = (rand() % candidate) + 1; b = (rand() % candidate) + 1; c = (rand() % candidate) + 1; d = (rand() % candidate) + 1; if (a == b || a == c || a == d || b == c || b == d || c == d) i = 1; else i = 0; } cout

So I know there is other solutions for this problem (I searched it online before) they use for loop:

#include

using namespace std;

int main() {

srand(time(NULL));

int finalists[4] = {0};

cout

for(int i = 0; i

bool inValid = true;

while(inValid) {

inValid = false;

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

for(int j = 0; j

if(finalists[i] == finalists[j]) {

inValid = true;

}

}

}

cout

}

}

But my problem is I haven't learnt array yet. Also, I want to know why my method can't work.

Anyone could help me out??? IDK what part I got wrong..

Thank you so much!

(((((P.SIf you could also explain the second method that would be helpful!!

I don't got why they put while loop b/t those two for loop? what's the usage of it?

Also, what is the meaning of the if requirement (finalist[i]==finalist[j])inside of the inner for loop .))))))

13. You have four identical prizes to give away and a pool of 25 finalists. The final- ists 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. 13. You have four identical prizes to give away and a pool of 25 finalists. The final- ists 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

Exercise

Answered: 1 week ago

Question

What are the major social responsibilities of business managers ?

Answered: 1 week ago

Question

What are the skills of management ?

Answered: 1 week ago