![]() |
| | #1 |
| Registered User Join Date: Feb 2008
Posts: 15
| Need help with a program, theres something in it for you Your favorite tv game show “The Price is Write” has decided to make an electronic version of their game show. You have been assigned the task of writing a program for ‘The Dice Game’. On the show, a contestant plays ‘The Dice Game’ in hopes of winning a new car! The price of the car only contains digits between 1 and 6(including 1 and 6). There are 6 digits in the price of the car ($_ _ _ _ _ _). The contestant is given 6 dice to roll, one for each digit. After rolling the first die (representing the first digit in the price), the contestant then states whether they think the digit in the actual price of the car is higher, lower or the same as the dice number. This pattern is followed for each of the digits in the price. In your main function, use a while loop to call the functions rollDice() and guessNum() until you have rolled the dice and made guesses for all digits in the price of the car. Your program should print a statement and exit if an incorrect guess is made or any number other than –1,0,or 1 is entered. rollDice() should return a random integer between 1 and 6 (for each side of the dice cube) to the main function. To generate a random number, include the following code: #include<stdlib.h> #include<time.h> int random_number = 0; srand(time(NULL)); random_number = (rand() % 6) +1; You should pass the random dice number and the digit in the actual price of the car into guessNum() and return a flag that would allow you to exit the while loop in the main program if you guess incorrectly. guessNum() should ask the user to enter –1 for less than the die value, 0 for same as, and 1 for higher than. Based on what the user enters, it should then evaluate if that guess is correct and change the flag value if necessary. To help you write and debug your code, we are going to cheat a little at ‘The Dice Game’. Instead of guessing some unknown price, you will decide what the price of the car is and put that in your code (Ex: int price =123456 and set a counter to the number of digits in your price (Ex: int counter = 6 . This should help you to ensure that your program is running correctly.Hint: The following code helps you to grab one digit at a time from the price. To grab the first two digits from the price $123456, int digit = 123456 / (10^5); // now digit is equal to 1 123456 - (digit * (10^5) ) = 23456; digit = 23456 / (10^4) // now digit is equal to 2 2345 - (digit * (10^4) ) = 345; Sample: bash-3.1$ gcc hw5.c bash-3.1$ ./a.out You rolled a 6. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: -1 That is correct! 1 is less than 6 You rolled a 5. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: -1 That is correct! 2 is less than 5 You rolled a 3. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: 0 That is correct! 3 is equal to 3 You rolled a 4. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: 0 That is correct! 4 is equal to 4 You rolled a 4. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: 1 That is correct! 5 is bigger than 4 You rolled a 3. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: 1 That is correct! 6 is bigger than 3 YOU HAVE WON A BRAND NEW CAR WORTH $123456!!!! bash-3.1$./a.out You rolled a 1. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: -1 That guess is incorrect. The actual digit in the price is 1. Goodbye. bash-3.1$./a.out You rolled a 3. What is the actual digit in the price? Press –1 for lower, 0 for equal to, and 1 for higher: 6 That number is out of range. Goodbye. |
| engstudent363 is offline | |
| | #2 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| This makes me mad. First of all, please put the dollar bills back into your pocket. Thanks. Your nickname is "engstudent363." I assume that means "engineering student," although I suppose you could be an "English student." If you are an English student, may I suggest dropping the class? It clearly isn't what you're interested in, and believe me, at this rate you'll be paying thousands by graduation time. If you are an engineering student, please, don't just drop the class, but switch majors. I really don't want to live in a world with products designed by "engineers" who bought every credit they received. It puts engineering as well as higher education to disgrace. |
| brewbuck is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| program quits unexpected | skelesp | C Programming | 34 | 12-10-2008 09:10 AM |
| Issue with program that's calling a function and has a loop | tigerfansince84 | C++ Programming | 9 | 11-12-2008 01:38 PM |
| This is a simple program.. Help me please I think it has an error.. | lesrhac03 | C Programming | 4 | 02-21-2008 10:39 AM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |