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

This is a discussion on Need help with a program, theres something in it for you within the C Programming forums, part of the General Programming Boards category; I've been stuck on this program trying to get it to work for the past 2 days and haven't gotten ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    15

    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.

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program quits unexpected
    By skelesp in forum C Programming
    Replies: 34
    Last Post: 12-10-2008, 09:10 AM
  2. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21