Question

In: Computer Science

This is C Project 1: Due: February 10th at midnight Design and implement an application that...

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

Solutions

Expert Solution

#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\n", num1,num2,num3);
if(num1 == num2 && num2 == num3){
printf("All three numbers are the same\n");
}
else if(num1 == num2 || num2 == num3 || num3 == num1){
printf("Any two numbers are the same\n");
}
else{
printf("All three numbers are not the same\n");
}
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 Solutions

A, B:   Design and Implement a C# windows form application to ask the user for 10...
A, B:   Design and Implement a C# windows form application to ask the user for 10 integer numbers, sort them in ascending order and display the sorted list. Use bubble sort technique to sort the array elements and do not use any built-in sort method to sort the array elements.                                                        [02] C:    Test and evaluate your program by inputting variety of values.
A, B:    Design and Implement a C# windows form application to encrypt and decrypt text....
A, B:    Design and Implement a C# windows form application to encrypt and decrypt text. The application use to receive a string and display another encrypted string. The application also decrypt the encrypted string. The approach for encryption/decryption is simple one i.e. to encrypt we will add 1 to each character, so that "hello" would become "ifmmp", and to decrypt we would subtract 1 from each character.    C:   Test and evaluate application by applying different strings.      ...
Car Rental Management System in C++ The aim of this project is to design and implement...
Car Rental Management System in C++ The aim of this project is to design and implement a computerized Car Rental Management System for a company called COEN244Cars. The company rents two types of cars: standard and luxury cars. A car is identified by a car identification number (int), a type (string), and a flag that indicates whether the car is currently available or not. The company distinguishes between three types of customers: regular customers, corporate customers, and VIPs (Very Important...
Design and implement a C++ Application that: Interactively input: Employee First Name Employee Last Name Employee...
Design and implement a C++ Application that: Interactively input: Employee First Name Employee Last Name Employee id Employee hours worked per week Employee Pay Rate Menu with Option to: Print out Employee Report in the following report format Search for an Employee Display the Report in Sorted based on Last Name or ID Calculate the Pay Quit Criteria: Be sure to use Parallel Arrays to Store the Employee Information Output must be formatted and line up with the column header...
Design and implement an application that reads an integer value and prints the sum of all...
Design and implement an application that reads an integer value and prints the sum of all even integers between 2 and the input value, inclusive. Print an error message if the input value is less than 2 and prompt accordingly so that the user can enter the right number. Your program file will be called YourLastNameExamQ2
Java - Design and implement an application that creates a histogram that allows you to visually...
Java - Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values. The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered. Sample...
Use Verilog to design and implement a function as  c = c+∑b*ai, i is from 1 to...
Use Verilog to design and implement a function as  c = c+∑b*ai, i is from 1 to 8. Here ai is stored in a SRAM with width as 16 and depth as 8 (8 rows of 16‐bit data), and b is stored in a 16‐bit register. c is initialized as 0.
C++Design and implement a program (name it LinearBinarySearch) to implement and test the linear and binary...
C++Design and implement a program (name it LinearBinarySearch) to implement and test the linear and binary search algorithm discussed in the lecture slides. Define method LinearSearch() to implement linear search of an array of integers. Modify the algorithm implementation to count number of comparisons it takes to find a target value (if exist) in the array. Define method BinarySearch() to implement binary search of an array of integers. Modify the algorithm implementation to count number of comparisons it takes to...
Design and implement an application that can compute the weekly pay for different students at a college.
In Java Design and implement an application that can compute the weekly pay for different students at a college. Students (all with a name, major, GPA) can be undergraduate or graduate students. Undergraduate students can be volunteers to be tuto rs or teaching assistants. Graduate students can be teaching assistants or research assistants. Volunteer tuto rs are not paid anything. Undergraduate teaching assistants are paid $15 per hour and can work a maximum of 20 hours per week. Graduate teaching assistants...
programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT