Thread: parameter placeholders

  1. #1
    UpTooLate
    Join Date
    Feb 2008
    Location
    New York
    Posts
    32

    Question parameter placeholders

    Hi
    I am not really sure how parameter placeholders work and I was wondering if someone could explain it to me. I am dealing with classes and I don't really understand how they work together.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Are you talking about default arguments?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    UpTooLate
    Join Date
    Feb 2008
    Location
    New York
    Posts
    32

    Question this is the program itself

    I'm not really sure... Here is what my program looks like so far.
    It is supposed to implement a cash register.
    The last function (AmountToMakeChangeFor) is supposed to take a parameter placeholder double which represents the amount to make
    change for, and fills the number of each denomination correctly, and the program should run like this (based upon how many non-zero amounts of each denomination you should receive in return:
    Twenties: 2
    Fives: 1
    Ones: 1
    Quarters: 2
    Dimes: 1
    Pennies: 3


    I am quite baffled by this right now!


    Code:
    #include <iostream>
    
    using namespace std;
    
    class Change
    {
          public:
                 void showEach();
                 void setEachToZero();
                 double AmountToMakeChangeFor();
                 
                 
          private:
                  int numTwenties;
                  int numTens;
                  int numFives;
                  int numOnes;
                  int numQuarters;
                  int numDimes;
                  int numNickels;
                  int numPennies;
                  
    };
    
    int main()
    {
        double amount; // declare a double named "amount" in MAIN
        double tender; // declare a double named "tender" in MAIN
        cout << "Please enter the amount of the item: "; //asks the user to enter price of item
        cin >> amount; // inputs this as "amount"
        cout << endl; // end line
        cout << "Please enter the amount tendered: "; // asks the user to enter the amount received
        cin >> tender; // inputs this as "tender"
        cout << endl; // end line
        
        if (tender - amount > 0)
        {
             double amt_p = tender - amount;
        }
        else if (tender - amount < 0)
        {
             double amt_p = 0;
             cout << "You owe an additional amount of " << amount - tender << endl;
        }           
        else
        {
            double amt_p = 0;
            cout << "You broke even." << endl;
        }
        
        
        
        
        
        system("pause");
        return 0;
    }
    
    void Change::showEach() // will show the number of each amount
    {
         if (numTwenties > 0) //if the # of 20s is greater than 0
         {
            cout << "Twenties: " << numTwenties << endl; //output the number
         }
         if (numTens > 0) // if the # of 10s is greater than 0
         {
            cout << "Tens: " << numTens << endl; //output the number
         }
         if (numFives > 0) // if the # of 5s is greater than 0
         {
            cout << "Fives: " << numFives << endl; //output the number
         }
         if (numOnes > 0) // if the # of 1s is greater than 0
         {
            cout << "Ones: " << numOnes << endl; //output the number
         }
         if (numQuarters > 0) // if the number of .25s is greater than 0
         {
            cout << "Quarters: " << numQuarters << endl; // output the number
         }
         if (numDimes > 0) // if the # of .10s is greater than 0
         {
            cout << "Dimes: " << numDimes << endl; // output the number
         }
         if (numNickels > 0) // if the # of nickels is greater than 0
         {
            cout << "Nickels: " << numNickels << endl; // output the number
         }
         if (numPennies > 0) // if the number of pennies is greater than 0
         {   
            cout << "Pennies: " << numPennies<< endl; // output the number
         } 
    }
    
    void Change::setEachToZero()
    {
         numTwenties = 0;
         numTens = 0;
         numFives = 0;
         numOnes = 0;
         numQuarters = 0;
         numDimes = 0;
         numNickels = 0;
         numPennies = 0;
    }
    
    void Change::AmountToMakeChangeFor(double amt_p)
    {
         numTwenties = (amt_p / 20);
         amt_p = (amt_p - (numTwenties * 20);
         numTens = (amt_p / 10);
         amt_p = (amt_p - (numTens * 10);
         numFives = (amt_p / 5);
         amt_p = (amt_p - (numFives * 5);
         numOnes = (amt_p /1);
         amt_p = (amt_p - (numOnes * 1);
         numQuarters = (amt_p / .25);
         amt_p = (amt_p - (numQuarters * .25);
         numDimes = (amt_p / .10);
         amt_p = (amt_p - (numDimes / .10);
         numNickels = (amt_p / .05);
         amt_p = (amt_p - (numNickels * .05);
         numPennies = (amt_p / .01);
    }

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    For one thing your function declarations don't match:
    Code:
    class Change {
    ...
        double AmountToMakeChangeFor();
    };
    
    void Change::AmountToMakeChangeFor(double amt_p)
    As to what you mean by placeholders, it is quite unclear. All you need is a pretty ordinary member function that takes a double (which may cause problems because of its imprecision - may-be you should multiply the input by 100 and round it to integer first) and returns void.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Maybe I'm going blind, but I don't see you using the Change class anywhere in main().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my error is storage class specified for parameter
    By meli in forum C Programming
    Replies: 5
    Last Post: 03-27-2009, 12:06 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM