Thread: trying to make change from the price of the item and the amount given. please help!!!

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    1

    Unhappy trying to make change from the price of the item and the amount given. please help!!!

    /*This lab will calculate and display change*/\



    #include <stdio.h>


    main ()
    {
    float change,
    price,
    amt_paid;

    int twenties = 0,
    tens = 0,
    fives = 0,
    ones = 0,
    quarters = 0,
    dimes = 0,
    nickels = 0,
    pennies = 0;


    printf("\nPlease enter Price of Item:");
    scanf("%f", &price);

    printf("\nPlease enter Amount Paid:");
    scanf("%f", &price);

    /* Calculations for change*/

    change = amt_paid - price;
    int(change*=100);

    printf("\nCHANGE = $ ");
    scanf("%f", &change);


    while (change>0)
    {

    if (change > 20)
    {++twenties;
    break ();}


    else if (change > 10)
    {++tens;
    break ();}

    else if (change > 5)
    {++fives;
    break ();}

    else if (change > 1)
    {++ones;
    break ();}

    else if (change > .25)
    {++quarters;
    break ();}

    else if (change > .10)
    {++dimes;
    break ();}

    else if (change > .05)
    {++nickels;
    break ();}

    else if (change > .01)
    {++pennies;}






    }

  2. #2
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Exclamation

    Peeps wonder why I sometimes come down on newbies, its not rying to be unkind... I am simply trying to say, "Think for yourself".

    Think about it... how much is a quarter worth... 25 cents!
    A dime... 10 cents!
    ect. ect.

    Code:
    int cents = 0;
    I allways try to think for at leaste 5 minutes before posting... the apparent answer (such as 5 ints for each type of change) is uduslly not the correct one, try to train yourself to think about more efficient possibuilities and you will allways acheive.

    SPH

    - Written with a burnt hand.

  3. #3
    Registered User minime6696's Avatar
    Join Date
    Aug 2001
    Posts
    267

    Lightbulb think

    think about it... its not hard, think, if you REALLY using your whole brain, cannot figure it out, then read the code, but if u CAN than dont read the code I give you.

    ...

    Okay if u are readinf this u didnt get it:

    use simple division.
    You scan the privce into int cents.

    then simply devide by the value of the coin...

    cents / 25; // quarters

    sometimes I feal as if the school system has truely failed us.

    no offence to you.

    SPH

Popular pages Recent additions subscribe to a feed