enter not returning line?!
Jan 27, 2013 at 11:33pm UTC
ok so now the only thing I need to know how to do is that if the return is hit and no entry is made in the initial input line the cin will return as zero and run the while loop to produce cost = 0 tendered = 0 change = 0?! please help
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#include <cmath>
#include <cstdlib>
#include <cctype>
// Placed all std in right #include
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;
#include <iomanip>
using std::setprecision;
using std::setw;
int main()
{
// Beginning information on lab and programmer
cout << endl;
cout << "Lab: 2" << endl;
cout << "Programmer: Joshua Henry" << endl;
cout << endl;
// Declare variables for cost, pay and change
double pur = 0;
double tend = 0;
int change;
double balAmt = 0.0;
const int FIFTY = 5000;
const int TWENTY = 2000;
const int TEN = 1000;
const int FIVE = 500;
const int ONE = 100;
const int FIFTYCENT = 50;
const int QUARTER = 25;
const int DIME = 10;
const int NICKEL = 5;
const int PENNY = 1;
int fiftyBill = 0;
int twentyBill = 0;
int tenBill = 0;
int fiveBill = 0;
int oneBill = 0;
int fiftyCent = 0;
int quarterCent = 0;
int dimeCent = 0;
int nickelCent = 0;
int pennyCent = 0;
// Declare variables to compute what change given
// Ask the user to input both purchase and tendered amount
cout << "Please enter the Purchase amount and amount tendered(seperated by a space): \n" ;
cin >> pur >> tend;
cout << endl;
int cost = pur * 100;
int pay = tend * 100;
// make operations to determine how many bills the change entitles
change = pay - cost;
while (change > 0)
{
if (change >= 5000)
{
fiftyBill = change / FIFTY;
change = change - (FIFTY * fiftyBill);
}
else if (change >= 2000)
{
twentyBill = change / TWENTY;
change = change - (TWENTY * twentyBill);
}
else if (change >= 1000)
{
tenBill = change / TEN;
change = change - (TEN * tenBill);
}
else if (change >= 500)
{
fiveBill = change / FIVE;
change = change - (FIVE * fiveBill);
}
else if (change >= 100)
{
oneBill = change / ONE;
change = change - (ONE * oneBill);
}
else if (change >= 50)
{
fiftyCent = change / FIFTYCENT;
change = change - (FIFTYCENT * fiftyCent);
}
else if (change >= 25)
{
quarterCent = change / QUARTER;
change = change - (QUARTER * quarterCent);
}
else if (change >= 10)
{
dimeCent = change / DIME;
change = change - (DIME * dimeCent);
}
else if (change >= 5)
{
nickelCent = change / NICKEL;
change = change - (NICKEL * nickelCent);
}
else if (change >= 1)
{
pennyCent = change / PENNY;
change = change - (PENNY * pennyCent);
}
}
balAmt = tend - pur;
cout.setf(ios::fixed|ios::showpoint);
cout << setprecision(2);
cout << endl;
cout << "For a purchase of " << pur << " the amount tendered is " << tend << endl;
cout << "Your change will be $" << balAmt << endl;
if (fiftyBill != 0)
cout << fiftyBill << " $50 bill" << endl;
if (twentyBill != 0)
cout << twentyBill << " $20 bill" << endl;
if (tenBill != 0)
cout << tenBill << " $10 bill" << endl;
if (fiveBill != 0)
cout << fiveBill << " $5 bill" << endl;
if (oneBill != 0)
cout << oneBill << " $1 bill" << endl;
if (fiftyCent != 0)
cout << fiftyCent << " 50 cent coin" << endl;
if (quarterCent != 0)
cout << quarterCent << " 25 cent coin" << endl;
if (dimeCent != 0)
cout << dimeCent << " 10 cent coin" << endl;
if (nickelCent != 0)
cout << nickelCent << " 5 cent coin" << endl;
if (pennyCent != 0)
cout << pennyCent << " 1 cent coin" << endl;
cout << endl;
}
Last edited on Jan 28, 2013 at 2:19am UTC
Topic archived. No new replies allowed.