This is C Project 1: Due: February 10 th at midnight Design and implement an app
ID: 3790092 • Letter: T
Question
This is C
Project 1:
Due: February 10th at midnight
Design and implement an application that simulates a simple slot machine in which three numbers between 0 and 9 are randomly selected and printed side by side. Print an appropriate statement if all three of the numbers are the same, or if any two of the numbers are the same. Continue playing until the user chooses to stop.
15 points – source code formatted nicely
15 points – comments
15 points – output formatted nicely
10 points – generates different random numbers each loop
15 points – statement if all three numbers are the same
15 points – statement if any two numbers are the same
15 points - play until user wants to stop
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1,num2,num3;
char ch = 'y';
srand(time(NULL));
while(ch == 'y' || ch == 'Y' ){
// seed the random number generator
num1 = rand()%10;
num2 = rand()%10;
num3 = rand()%10;
printf("%d %d %d ", num1,num2,num3);
if(num1 == num2 && num2 == num3){
printf("All three numbers are the same ");
}
else if(num1 == num2 || num2 == num3 || num3 == num1){
printf("Any two numbers are the same ");
}
else{
printf("All three numbers are not the same ");
}
printf("Do you want to play again (y/n): ");
scanf(" %c", &ch);
}
return 0;
}
Output:
sh-4.2$ gcc -o main *.c
sh-4.2$ main
8 7 1
All three numbers are not the same
Do you want to play again (y/n): y
0 5 5
Any two numbers are the same
Do you want to play again (y/n): y
5 4 2
All three numbers are not the same
Do you want to play again (y/n): y
8 9 3
All three numbers are not the same
Do you want to play again (y/n): y
5 4 4
Any two numbers are the same
Do you want to play again (y/n): n
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.