# Thread: Need help with a program, theres something in it for you

1. ## Need help with a program, theres something in it for you

I've been stuck on this program trying to get it to work for the past 2 days and haven't gotten it to run properly. I have no idea what I need to do and I need some serious help. If someone can get me a working program there will be some money in it for them. I'll send it into your paypal account. Probably close to \$30 although the program must do exactly as specified. Any problems with the program will get a reduction in the amount paid to him/her. Here's what I need:

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.  Popular pages Recent additions 