1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <iostream>
#include <string>
using namespace std;
string askForName();
int askForCoins(string);
int TotalAndWrite();
int main()
{
string userName, n;
char choice;
cout << "Hello! My name is Brendan Bohlin; Welcome to my Coin Counter Program!" << endl << endl;
userName = askForName();
cout << "Hi " << userName << "!" << endl << endl;
do
{
askForCoins(userName);
cout << "Would you like to run the program again?" << endl << "If you would like to run the program again, please enter any key." << endl;
cout << "If you would like to end the program please enter 'N' or 'n'" << endl;
cin >> choice;
}
while ((choice != 'n')&&(choice !='N'));
cout << "Goodbye!" << endl;
}
string askForName()
{
string userName;
cout << "Please enter your name: ";
getline (cin, userName);
return userName;
}
int askForCoins(string userName)
{
int penny, nickel, dime, quarter;
int *ptrP = &penny;
int *ptrN = &nickel;
int *ptrD = &dime;
int *ptrQ = &quarter;
cout << "Please enter the number of QUARTERS, DIMES, NICKELS, and PENNIES" << endl << "that you have with you , " << userName << endl;
cout << "Quarters: ";
cin >> quarter;
cout << endl << "Dimes: ";
cin >> dime;
cout << endl << "Nickels: ";
cin >> nickel;
cout << endl << "Pennies: ";
cin >> penny;
}
int TotalAndWrite(int *ptrP, *ptrQ, *ptrN, *ptrD)
{
int q, d, n, p;
q = *ptrQ * 0.25;
d = *ptrD * 0.10;
n = *ptrN * 0.05;
p = *ptrP * 0.01;
cout << "Quarters: " << quarters << " $" << q << endl;
cout << "Dimes: " << dimes << " $" << d << endl;
cout << "Nickels: " << nickels << " $" << n << endl;
cout << "Pennies: " << pennies << " $" << p << endl;
}
|