I need to create a lottery simulator. The program must allow the user to enter t
ID: 3574923 • Letter: I
Question
I need to create a lottery simulator. The program must allow the user to enter the starting value, the ending value, and the number of times to generate a random number. The program should store the inputs in variables and use them in the program.
Requirements:
Display input messages to get the starting value, ending value, and number of times to generate a number.
Use a LOOP instruction to generate a random number between the start and end values and display the randomly generated number.
The program should display the lottery number generated for each loop iteration. For example, the user wants to run the lottery 100 times with the starting value of 1 and the ending value of 999 where each time the lottery generates a number it gets displayed on the screen.
Change the color of the background and text for your program using the Irvine Library function.
Explanation / Answer
#include<stdio.h>
int main()
{
int start,end,value,a,number;
printf("Enter starting and end values:");
scanf("%d,%d",&start,&end);
printf("Enter number of times to gernerate a random value:");
scanf("%d",&value);
for(a=start;a<=value;a++)
{
number=random()%end;
printf("%d ",number);
}
return 0;
}
OUTPUT:
Enter starting and end values: 1,100
Enter number of times to gernerate a random value: 5
83
86
77
15
93
Note: Output differs every time
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.