Answer is 19:16:15:16
PLease help me to understand how to get this answer
The following code is from a game, which generates a set of 4 random numbers.
Yallav is playing this game, help him to identify the correct option(s) out of the
four choices given below as the possible set of such numbers generated from
the program code so that he wins the game. Justify your answer.
#include <iostream.h>
#include <stdlib.h>
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int 1=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<“:” ;
POINT--;
}
}
Your program should not compile. It is ridden with errors. #include <iostream.h> ←should not work #include <stdlib.h> Use cstdlib in C++ void main ( )Invalid in C++ randomize( ) ;What that function is? int 1=1;invalid statement random(POINT) ;random()? what is it?
Well, I would run away from school which teaches that.
Answer is 19:16:15:16
from context of your code, I would say that there cannot be set output (because it is random).
I say that possible range of output depend of random() function definition (inclusive/exclusive, from 0/from 1).
If it is generates-from-0-to-parameter-exclusive then minimum number which can be generated is LOW and maximum is LOW+POINT-1.
So your example output can in theory be generated.
Then you need to provide what the functions randomize(); and random(POINT); are defined as. Otherwise, we're going to assume that it's completely random and there is no way to tell what the possible outputs are.
Then I would ask your instructor how you could possibly know since both answers are valid. As long as the four numbers are between 15 and 20 (maybe other numbers, but it's hard to tell), it is a valid answer according to the given information. Without any other information, there is no feasible way to differentiate between two potentially correct answers.
Edit: MiiNiPaa got it right in the below post. This is why it's so important for you to post your code within the [code][/code] tags.
Ow, damn, i didn't noticed POINT--. Well. Initial possible range of generated numbers is 15-19. Each next number have max range 1 less. So possible max values — 19:18:17:16
one more random question.
In the following program, if the value of Guess entered by the user is 65, what will be the expected output(s) from the following options (i), (ii), (iii) and (iv)?
#include <iostream.h>
#include <stdlib.h>
void main()
{
int Guess;
randomize();
cin>>Guess;
for (int I=1;I<=4;I++)
{
New=Guess+random(I);