Change Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JDK721
    New Member
    • Oct 2006
    • 14

    #1

    Change Program

    I need to write a program that will calucate how many quarters, dimes, nickels, and pennies a certain amount of cents will have. So for example, you enter 90 cents. That would be 3 quarters, 1 dime, 1 nickel, 0 pennies. I have this so far, im having trouble with the MATH part. The only thing working is the quarters. I've honestly tried everything, and have been working on this for hours.

    #include <iostream.h>

    main()
    {
    int quarters;
    int dimes;
    int nickels;
    int pennies;
    int number;

    cout << "Enter a number. " << '\n';
    cin >> number;

    quarters = number / 25;
    dimes = number - (quarters * 25) / 10;
    nickels = number - (quarters * 25) / (dimes * 10) / 5;
    pennies = number - (quarters * 25) / (dimes * 10) / (nickels * 5);

    cout << "Quarters - " << quarters << '\n';
    cout << "Dimes - " << dimes << '\n';
    cout << "Nickels - " << nickels << '\n';
    cout << "Pennies - " << pennies << '\n';
    cout << '\n';
    system("PAUSE") ;
    return 0;
    }
  • manontheedge
    New Member
    • Oct 2006
    • 175

    #2
    you can use the modulus operator, the percent sign...

    quarter = .25
    number % quarter // for quarters...

    then, however many times .25 goes into the number, that's the number of quarters, and the modulus then gives the remainder ( what is too small to be a quarter ), then do it again for dimes...

    dime = .1
    afterQuarters = number - ( numQuarters*qua rter )
    afterQuarters % dime

    anyway, that's the general idea. Hopefully it makes sense. If you've never used the modulus operator, look it up on wikipedia or somewhere else. Once you know how to use it, this program will be fairly easy.

    Comment

    • momotaro
      Contributor
      • Sep 2006
      • 357

      #3
      hint use "%" to compute u r rest!!!

      Comment

      Working...