Thread: I am not sure where to go from here

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    3

    I am not sure where to go from here

    So I was working on this assignment for class and got this far. The output doesn't match the examples and I have been fiddling with it for hours trying to figure out what is wrong. Any pointers?
    Attached Files Attached Files
    • File Type: c hw4.c (1,020 Bytes, 187 views)

  2. #2
    Registered User
    Join Date
    Aug 2016
    Posts
    13
    Could you explain what are you trying to achieve?

  3. #3
    Registered User
    Join Date
    Sep 2016
    Posts
    3
    I dont think my explanation will make sense so I am just going to write down what it says:
    Write a program to mimic this process. Ask the user to enter the size (in ounces) of the juice containers you buy, as well as the price of those containers (in dollars). Then prompt the user to enter how many times the roommate took juice. Finally, read the amount the roommate took each time. Every time the total value of the juice equals or exceeds $10, print out “Your roommate owes you $10.00.” After all the numbers are entered, if the roommate owes any money, print out the value owed.

    And heres an example:

    What is the weight (in oz.) of the original container of OJ?
    64
    What is the cost of the original container of OJ in dollars?
    3.79
    How many times did your roommate take your juice?
    10
    How much juice did your roommate take this time (in oz.)?
    30
    How much juice did your roommate take this time (in oz.)?
    34
    How much juice did your roommate take this time (in oz.)?
    24
    How much juice did your roommate take this time (in oz.)?
    40
    How much juice did your roommate take this time (in oz.)?
    64
    Your roommate owes you $10.00.
    How much juice did your roommate take this time (in oz.)?
    64
    How much juice did your roommate take this time (in oz.)?
    64
    How much juice did your roommate take this time (in oz.)?
    18
    Your roommate owes you $10.00.
    How much juice did your roommate take this time (in oz.)?
    20
    How much juice did your roommate take this time (in oz.)?
    20
    Your roommate owes you $2.38.

  4. #4
    Registered User
    Join Date
    Sep 2016
    Posts
    3
    This is an assignment so I do want to do this on my own just cant see where i went wrong and wanted some tips

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Code:
                if (calculation >= 10){
                    printf("Your roommate owes you $10.00.\n");
                    calculation = 0;
    It should be
    calculation = calculation - 10.0;

    Also, try naming your variables better.
    For example,

    amountowed = amountowed + ( ounces * priceperoz );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Tags for this Thread