3 User Defined Funtions
Apr 11, 2014 at 4:46pm UTC
So I am taking this C++ course and I am currently dying in it... So help would be lovely. I am supposed to add 3 user-defining functions and at least one of those functions should have a variable passed by reference. Also, I thought it worked, but it actually doesn't. And I have no idea how to fix it...
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
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
double total=0;
int quarters=0;
int dimes=0;
int nickles=0;
int pens;
double change = 0;
int twd =0;
int td = 0;
int fd = 0;
int od = 0;
string choice = "y" ;
//The loop back after the choice of yes.
while (choice == "y" || choice == "Y" )
{
cout << "Enter amount of change you wish to convert: <max of $99.99> " ;
cin >> total;
while (total > 100 || total == 0) //total has to be less than 100 or else it will ask you again.
{
cout<<"Enter amount of change you wish to convert: <max of $99.99> " ;
cin >> total; //Entering the amount.
}
change = total*100;
twd = change/2000;
change = change - (twd * 2000);
td = change/1000;
change = change - (td * 1000);
fd = change/500;
change = change - (fd * 500);
od = change/100;
change = change - (od * 100);
quarters = change/25;
change = change - (quarters * 25);
dimes = change/10;
change = change - (dimes * 10);
nickles = change/5;
change = change - (nickles * 5);
pens = change/1;
change = change - (pens * 1);
cout << "\n\nBills Returned:\t\t" ;
if (twd != 0)
cout<<"Twentys: " <<twd<<"\n" ;
if (td != 0)
cout<<"\t\t\tTens: " <<td<<"\n" ;
if (fd != 0)
cout<<"\t\t\tFives: " <<fd<<"\n" ;
if (od !=0)
cout<<"\t\t\tOnes: " <<od<<"\n" ;
if (quarters != 0)
cout << "\n\nCoins Returned:\t\tQuarters: " << quarters << "\n" ;
if (dimes != 0)
cout << "\t\t\tDimes: " << dimes << "\n" ;
if (nickles != 0)
cout << "\t\t\tNickles: " << nickles << "\n" ;
if (pens != 0)
cout << "\t\t\tPennies: " << pens << "\n" ;
cout << "\n\nDo you have more change to convert? <Y or N>: " ;
cin >> choice;
}
}
Apr 11, 2014 at 4:58pm UTC
I am supposed to add 3 user-defining functions
I don't see any functions. Suggestion. Prompting for user input usually makes a good function.
I thought it worked, but it actually doesn't.
Please be specific about what doesn't work.
It seemed to work for me with a few values I tried, except for 0.01
It seems to think a penny is a bill:
Bills Returned: Pennies: 1
Topic archived. No new replies allowed.