Coin Counter

Program that reads a set of integer values entered on the keyboard, counts them like a coin counting machine, and then prints a report containing the subtotal of each valid coin value and the grand total for all of the valid coins. Valid coin denominations are the integers 1, 5, 10, 25, and 50.

For this I have completed the program. But when it goes to the command prompt screen its blank. I know that I am not supposed to prompt the user for any data. But how am I to know if the program is correct?



// Include Files
#include <iostream>
#include <iomanip>

// Constants
const int SENTINEL = 999;

using namespace std;

// Function Prototypes
void countCoins(int &pennyCount, int &nickelCount, int &dimeCount,
int &quarterCount, int &halfDollarCount, int &invalidCount);
void produceCoinReport(int pennyCount, int nickelCount, int dimeCount,
int quarterCount, int halfDollarCount, int invalidCount);


// ############################################################
int main(void)
{
int pennyCount;
int nickelCount;
int dimeCount;
int quarterCount;
int halfdollarCount;
int invalidcoincount;


countCoins (pennyCount, nickelCount, dimeCount,quarterCount,halfdollarCount,invalidcoincount);
produceCoinReport (pennyCount, nickelCount, dimeCount,quarterCount,halfdollarCount,invalidcoincount);



return 0;
} // End main


// ############################################################
void countCoins(int &pennyCount, int &nickelCount, int &dimeCount,
int &quarterCount, int &halfDollarCount, int &invalidCount)
{
int thisCoin = 0;
while (thisCoin != SENTINEL);

{
cin >> thisCoin;
if (thisCoin == 1)
pennyCount++;
else if (thisCoin == 5)
nickelCount++;
else if (thisCoin == 10)
dimeCount++;
else if (thisCoin == 25)
quarterCount++;
else if (thisCoin ==50)
halfDollarCount++;

// and fill in for the rest of the coin values

else if (thisCoin != SENTINEL) // if the coin is not a valid value and not the SENTINEL, increment the invalid count
invalidCount++;

}




} // End countCoins


// ############################################################
void produceCoinReport(int pennyCount, int nickelCount, int dimeCount,
int quarterCount, int halfDollarCount, int invalidCount)

{
int totalNumberofCoins;
int totalValueofCoins;


cout << setprecision(2) << totalNumberofCoins << endl;
cout << setprecision(2) << totalValueofCoins << endl;



cout << "Total number of coins encountered (both valid and invalid);";
cout << " Total number of invalid coins : ";
cout << "Coin denomination: (1) (5) (10) (25) (50);";
cout << "Total number of coins";
cout << "Denomination sun";
cout << "Grand total of all coin denominations :";




} // End produceCoinReport



while (thisCoin != SENTINEL);

Remove the semi-colon.

and..
this is really bad:
1
2
3
4
5
6
int pennyCount;
int nickelCount;
int dimeCount;
int quarterCount;
int halfdollarCount;
int invalidcoincount;


You are passing in uninitialised variables into your functions.
Last edited on
once i do that i get errors for the function. Is there anymore i should add?
What does "errors for the function" mean?

edit:
You second function (produceCoinReport) passes in all your coin counts but you do not use them.

Again you have unitialised variables here as well. Namely 'totalNumberofCoins' & 'totalValueofCoins'. You are missing out some maths here, to convert your coin count to value.

(note: with the changes i advised in my first post the correct values are now being passed into your second function).
Last edited on
I was getting errors with everything in the function like pennycount, nickelcount, etc. It says that these were not declared in the scope. Also I have another question, this is a different program because we don't prompt the user for any values, so how do I know that I am doing the program correctly, when I go and run it?
If your not asking for user input.... you have to specify arguments. objects need values in this case. you would specify them in the main... It seems counter intuitive, sure, but, write code that shows the computer asking questions and then display the answers. Give me a sample of your pseudo code... what you want the program to do. and i'll give you a simple form of the interaction.
I just took a second look at your program... I noticed some things... first thing... compiling your program...
there are 2 options under the debug tab if your using visual studio 2013.
F5 and Ctrl + F5.... you want to enter Ctrl+F5. This will allow you to see the results in your program. "Press any key to continue."
second thing, There is a very specific way to pass variables. The prototype, the function, the class, and the main have to agree. If you want to pass by reference you need the correct syntax for all of these parts of your program to agree.
look up "pass by reference examples" to get the right syntax.
Last edited on
I tried the Ctrl-F5 but I'ts causing my DEV C++ to stop working. Also, is what is have so far sufficient for the program? Because what I have for the very first program is still what I have for the program.
the program is crashing... does the control F5 work with a simple hello world program? I use visual studio 2013. look under the debug tab.
also you have to build first F7 then Ctrl+F5...
Last edited on
ashgirl112, if you're using DEV C++, hit F9 to compile your program. Or, there's a menu option to start debugging (if that's what you need) - just remember to set a breakpoint, first.

If you're still having trouble, I usually tutor people with extremely cheap rates, so go ahead and shout me an email at: sparkprogrammer@gmail.com
Topic archived. No new replies allowed.