Damn c++ class, help!!!

This is a discussion on Damn c++ class, help!!! within the A Brief History of Cprogramming.com forums, part of the Community Boards category; This has been bothering me, the teacher told me to make a cash register type program that you enter the ...

  1. #1
    gato_estupido
    Guest

    Angry Damn c++ class, help!!!

    This has been bothering me, the teacher told me to make a cash register type program that you enter the total price of stuff and how much the person paid and it tells you how many 20s 10s 5s 1s quarters dimes nickels and pennies to give as change. I thought oh thats f#cking easy so I started to make it. I see no reason why my code doesnt work and like me and 2 other kids are the only ones who he assigned it to because were the only ones way ahead. They cant figure out why it wont work either. I dont have the source code here right now but it as something like this:

    float change;
    float cash_they_gave;
    float TotalPrice;
    int twentys, tens, fives, ones, quarters, dimes, nickels;


    change = cash_they_gave - TotalPrice;

    while(change>=20)
    {
    change -= 20;
    twentys++;
    }

    while(change>=10)
    {
    change -= 10;
    tens++;
    }

    etc...


    it compiles and but doesnt give me the right numbers.
    please help and not turn my post pink.

  2. #2
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    that should be
    Code:
    while(change >= 0) {
           change -= 20;
           twenty++;
    }
    if (change < 0)
          change += 20;
    It might be easier to use integer division along with finding
    the remainder.

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Another option would be to use the search feature to find the other 3000 posts asking the exact same question.

  4. #4
    Blank
    Join Date
    Aug 2001
    Posts
    1,034
    My fault that code won't work.

    Code:
    if (change < 0) {
          change += 20;
          twenty--;
    }
    You should just use division and remainder.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 05:30 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. class errors
    By romeoz in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2003, 08:57 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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