Thread: Need a few hints.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    4

    Need a few hints.

    Hello everyone, ive been a lurker for a few months, signed up recently and now I have some questions.

    I am taking an into to c programming class, its going good so far and I am enjoying it. I was recently given a two part assignment. The first part involved writing a program to convert temperatures from C to F. It was initially challanging for me but after trying multiple items and reading books other than my assigned text, I was able to figure it out.

    The second part of the assignement has taken considerably longer time to plan and understand the logic. I have written and re-written the program so many times that it is to the point now that my previous drafts may have been closer to a solution than the current version. I am working with a peer in my class to solve this problem but we are only able to communicate at night, I was hoping someone might be able to give me a "nudge" so I can make a little progress before this evening.

    The problem is extremly basic but advanced for "week 2" me. The problem asks for a program that mimicks a cash register. The problem asks the user to input how many hamburgers and french fries the user would like. The program should then display the cost of the food, the cost of taxes and the total cost of food plus taxes. The program should continue to loop until the "sentinal value" of a negative number is placed for a "hamburger". Once the loop is exited the total number of orders/customers processed and the total number of sales+tax should be displayed.

    I understand there are way more advanced and streamlined ways to solve the following code, I have only been exposed to the "basics" and that is how the program will need to be written. I have a feeling that the error is in my math, using too many parenthesis or something like that or maybe my coding format. The professor admitted this problem may require us to "reach out" to peers in order to solve.

    I am using ideone online compiler, the code will compile, accept input but I get unexpected results and a handfull of scanf/format warnings. I am seeking hints like "way off", "pay more attention to line ", "your math is wrong", "this part is wrong" etc. If my issue is my understanding of float, double and int please just let me know because I'm obviously not getting it.

    I am not frustrated at all, just realized my time going forward would be better used with a hint or 2.

    Thanks.
    Code:
    #include<stdio.h>
    int main(void)
    {
            double ham=0;     //This is what I came up with for variables. Using double because it was compiling better for me.
     double fri=0;
     double tax=0;
            int cust =0;
     int total=0;
            
    while(ham>=0)                          //Used a while because it made sense and he hinted to wanting that on the assignment sheet, if ham is a negative number it should exit the loop
    {
    ham = 0, fri = 0, tax = 0;             //Initially Fries, Hamburger and Tax will be set to zero, as it loops it will zero out again only recording number of customers and toal sale amount each time.        
     
            printf("How many hamburgers would you like?:\n");  
            scanf("%d",&ham);
            
            printf("How many french fries would you like?:\n");
            scanf("%d",&fri);
                                                      //The printf below is where I think my problem is. It makes sense to me, its basic math but I think it is programmed wrong and screwing up my code.
            printf("Food cost: %d Cost of taxes: %d total cost: %d\n", (ham * 3.5) + (fri * 1.75), ((ham * 3.5) + (fri * 1.75)) * .06, (((ham * 3.5) + (fri * 1.75)) * .06) + ((ham * 3.5) + (fri * 1.75)));
     
    total = total + (((ham * 3.5) + (fri * 1.75)) * .06 + ((ham * 3.5) + (fri * 1.75)); // This should store in "total" the amount plus tax
     
    ++cust; // This should take "cust" which was previously set to zero up top and record each time inputs are entered until a negative number is placed in ham.
     
    }
     
    printf("Total amount of all sales: $%25.2f Total number of customers: %f\n", total, cust); //Once a negative number is placed in ham it should exit the while loop and printf the following, calling from the stored amount in total and cust
     
    return 0;
     
    }
    Last edited by millcityrider; 10-06-2011 at 08:30 AM. Reason: fixed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Helpful hints anyone?
    By PureMotive in forum C Programming
    Replies: 6
    Last Post: 02-23-2011, 02:13 PM
  2. Need some Hints on how to figure this out.
    By zerlok in forum C++ Programming
    Replies: 6
    Last Post: 02-26-2009, 02:46 PM
  3. Can you give me some hints?
    By mag_chan in forum C Programming
    Replies: 6
    Last Post: 12-05-2005, 04:04 PM
  4. Can you give me some hints?
    By mag_chan in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2005, 02:12 AM
  5. :) Help.. Please... I need some hints
    By NANO in forum C++ Programming
    Replies: 7
    Last Post: 04-16-2002, 03:06 AM