I'm confused on how to make my program show two different answers depending on what n

This is a discussion on I'm confused on how to make my program show two different answers depending on what n within the C Programming forums, part of the General Programming Boards category; Hello, I have two questions with the code i've written. (Hopefully this will make sense as well as the code ...

  1. #1
    Unregistered
    Guest

    I'm confused on how to make my program show two different answers depending on what n

    Hello,
    I have two questions with the code i've written. (Hopefully this will make sense as well as the code i've written.)This is my first experience with C programming and recently received a programming problem. "A grocery store is selling oranges for 9 cents a piece or one dollar per dozen." In the code i've written, the program multiplies the 9 * any number I input. My problem is I don't know how to make the program show that when i input 12 oranges, it will come to one dollar. I get 1.08 and i've tried different methods, but i'm very stumped on how to make every dozen 12, 24, 36, etc. become $1,2,3 instead of $1.08, 2.16, etc.
    Also how can i add a decimal to the amount in the correct slots for dollars and cents like
    $4.15 instead of $415 or $.36 instead of $36. Do i use a floater for that? I would really appreciate anyone giving me some pointers on this problem. Thank you....


    void function (int single_orange, int total_oranges);

    int main(void)
    {
    int single_orange, total_oranges;

    single_orange = 9;


    printf(" The price of a single orange is 9 cents \n");

    printf(" The price of a dozen oranges is 1 dollar \n");

    printf( "Enter the number of oranges you would like to purchase and press enter: ");
    scanf( "%d", &total_oranges );

    printf( "%d * %d \n", single_orange, total_oranges);

    printf("Your total comes to: $%d \n", single_orange * total_oranges);


    return 0;
    }

  2. #2
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Add another variable to track the price. Now then, while total_oranges is greater than 12, subtract 12 from total_oranges and add a dollar to price. After the while statement, total_oranges will be some number from zero to eleven. Multiply total_oranges with single_orange and add the result to price.

    Hope that helps,
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Make a program run at startup
    By cookie in forum Tech Board
    Replies: 2
    Last Post: 06-08-2007, 08:36 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. how to make my program run on windows start up
    By kantze in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 03-24-2007, 11:14 AM
  4. A doubt on how to make a program
    By louis_mine in forum C Programming
    Replies: 3
    Last Post: 08-20-2004, 11:16 AM
  5. Tell me a easy program to make PLEASE!! PLEASE PLEASE!!!!
    By oobootsy1 in forum C++ Programming
    Replies: 49
    Last Post: 08-11-2003, 11:30 PM

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