adding a loop ONTO a program

I'm supposed to edit my change due program so that it runs an endless number of recalculations, until either of the inputs is entered as zero or negative.
They want each prompt changed to reflect this -- they should include something like [enter 0 to exit]. I need to break out of the loop as soon as a zero or negative input is read -- and I must have 2 if-breaks. To put this another way, if I enter zero for the first input, I should NOT see a prompt for the second input, nor should I see the results of a calculation. It is possible for the VERY FIRST input to be zero -- that's if I start running the program and then decide to quit before having it do anything.

Here is my change due program:

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
 #include <iostream>
using namespace std;
#include <cmath>
#include <iomanip>



int main() {




  cout << endl << endl;

  int lendThisAmount;
  cout << "Enter in the amount of money lent: ";
  cin >> lendThisAmount;
  cout << endl;
  cin.ignore(1000, 10);

  int amountOffered;
  cout << "Enter in the amount of money offered: ";
  cin >> amountOffered;
  cout << endl;
  cin.ignore(1000, 10);

  float changeDue;

  int hundredThousandDollarBills, tenThousandDollarBills, fiveThousandDollarBills, thousandDollarBills, fiveHundredDollarBills, hundredDollarBills, fiftyDollarBills, twentyDollarBills, tenDollarBills, fiveDollarBills, twoDollarBills, oneDollarBills, quarters, dimes, nickels, pennies;    



    if (amountOffered > lendThisAmount){
        // They paid more than what's lendThisAmount, time to give out changeDue
        float changeDue = amountOffered - lendThisAmount;
        cout << "----------------------------------------------\n";
        cout << "Your change is $" << changeDue << endl;
        cout << "You get ";
       


        // hundredThousandDollarBills
        for (hundredThousandDollarBills = 0; changeDue >= 100000.00; hundredThousandDollarBills++)
           changeDue -= 100000.00;
        if (hundredThousandDollarBills) 
           cout << hundredThousandDollarBills << " hundred thousand dollar bills, " << endl;

        // tenThousandDollarBills
        for (tenThousandDollarBills = 0; changeDue >= 10000.00; tenThousandDollarBills++)
           changeDue -= 10000.00;
        if (tenThousandDollarBills) 
           cout << tenThousandDollarBills << " ten thousand dollar bills, " << endl;

        // fiveThousandDollarBills
        for (fiveThousandDollarBills = 0; changeDue >= 5000.00; fiveThousandDollarBills++)
           changeDue -= 5000.00;
        if (fiveThousandDollarBills) 
           cout << fiveThousandDollarBills << " five thousand dollar bills, " << endl;

        // thousandDollarBills
        for (thousandDollarBills = 0; changeDue >= 1000.00; thousandDollarBills++)
           changeDue -= 1000.00;
        if (thousandDollarBills) 
           cout << thousandDollarBills << " one thousand dollar bills, " << endl;

        // fiveHundredDollarBills
        for (fiveHundredDollarBills = 0; changeDue >= 500.00; fiveHundredDollarBills++)
           changeDue -= 500.00;
        if (fiveHundredDollarBills) 
           cout << fiveHundredDollarBills << " five hundred dollar bills, " << endl;

        // hundredDollarBills
        for (hundredDollarBills = 0; changeDue >= 100.00; hundredDollarBills++)
           changeDue -= 100.00;
        if (hundredDollarBills) 
           cout << hundredDollarBills << " hundred dollar bills, " << endl;

        // fiftyDollarBills
        for (fiftyDollarBills = 0; changeDue >= 50.00; fiftyDollarBills++)
           changeDue -= 50.00;
        if (fiftyDollarBills) 
           cout << fiftyDollarBills << " fifty dollar bills, " << endl;

        // twentyDollarBills
        for (twentyDollarBills = 0; changeDue >= 20.00; twentyDollarBills++)
           changeDue -= 20.00;
        if (twentyDollarBills) 
           cout << twentyDollarBills << " twenty dollar bills, " << endl;

        // tenDollarBills
        for (tenDollarBills = 0; changeDue >= 10.00; tenDollarBills++)
           changeDue -= 10.00;
        if (tenDollarBills) 
           cout << tenDollarBills << " ten dollar bills, " << endl;

        // fiveDollarBills
        for (fiveDollarBills = 0; changeDue >= 5.00; fiveDollarBills++)
           changeDue -= 5.00;
        if (fiveDollarBills) 
           cout << fiveDollarBills << " five dollar bills, " << endl;

        // twoDollarBills
        for (twoDollarBills = 0; changeDue >= 2.00; twoDollarBills++)
           changeDue -= 2.00;
        if (twoDollarBills) 
           cout << twoDollarBills << " two dollar bills, " << endl;


        // oneDollarBills
        for (oneDollarBills = 0; changeDue >= 1.00; oneDollarBills++)
           changeDue -= 1.00;
        if (oneDollarBills) 
           cout << oneDollarBills << " one dollar bills, " << endl;
        
        // quarters
        for (quarters = 0; changeDue >= 0.25; quarters++)
            changeDue -= 0.25;
        if (quarters)
            cout << quarters << " quarters, " << endl;
        
        // dimes
        for (dimes = 0; changeDue >= 0.10; dimes++)
            changeDue -= 0.10;
        if (dimes)
            cout << dimes << " dimes, " << endl;
        
        // nickels
        for (nickels = 0; changeDue >= 0.05; nickels++)
            changeDue -= 0.05;
        if (nickels)
            cout << nickels << " nickels, " << endl;
        
        // pennies, just for good measure
        for (pennies = 0; changeDue > 0.00; pennies++)
            changeDue -= 0.01;
        if (pennies)
            cout << pennies << " pennies.\n\n" << endl;
    } else {
        // They must have given exact change
        cout << "Thanks for using exact change!\n" << endl;
    }
    
    return 0;
}



So by endless calculations, is it supposed to output all the different possibilities of change I could be given? And does that mean I must exit out of the program manually? How would I go about this?
closed account (j2NvC542)
I am not sure if I understand it correctly, but you can check to see, if lendThisAmount == 0 and if it is, break out of the while loop.

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
#include <iostream>
using namespace std;
#include <cmath>
#include <iomanip>


int main() {

  cout << endl << endl;

  while (true) { // infinite loop
	  int lendThisAmount;
	  cout << "Enter in the amount of money lent: ";
	  cin >> lendThisAmount;
	  if (lendThisAmount == 0) break;
	  cout << endl;
	  cin.ignore(1000, 10);

	  int amountOffered;
	  cout << "Enter in the amount of money offered: ";
	  cin >> amountOffered;
	  cout << endl;
	  cin.ignore(1000, 10);

	  float changeDue;

	  int hundredThousandDollarBills, tenThousandDollarBills, fiveThousandDollarBills, thousandDollarBills, fiveHundredDollarBills, hundredDollarBills, fiftyDollarBills, twentyDollarBills, tenDollarBills, fiveDollarBills, twoDollarBills, oneDollarBills, quarters, dimes, nickels, pennies;    



		if (amountOffered > lendThisAmount){
		    // They paid more than what's lendThisAmount, time to give out changeDue
		    float changeDue = amountOffered - lendThisAmount;
		    cout << "----------------------------------------------\n";
		    cout << "Your change is $" << changeDue << endl;
		    cout << "You get ";
		   


		    // hundredThousandDollarBills
		    for (hundredThousandDollarBills = 0; changeDue >= 100000.00; hundredThousandDollarBills++)
		       changeDue -= 100000.00;
		    if (hundredThousandDollarBills) 
		       cout << hundredThousandDollarBills << " hundred thousand dollar bills, " << endl;

		    // tenThousandDollarBills
		    for (tenThousandDollarBills = 0; changeDue >= 10000.00; tenThousandDollarBills++)
		       changeDue -= 10000.00;
		    if (tenThousandDollarBills) 
		       cout << tenThousandDollarBills << " ten thousand dollar bills, " << endl;

		    // fiveThousandDollarBills
		    for (fiveThousandDollarBills = 0; changeDue >= 5000.00; fiveThousandDollarBills++)
		       changeDue -= 5000.00;
		    if (fiveThousandDollarBills) 
		       cout << fiveThousandDollarBills << " five thousand dollar bills, " << endl;

		    // thousandDollarBills
		    for (thousandDollarBills = 0; changeDue >= 1000.00; thousandDollarBills++)
		       changeDue -= 1000.00;
		    if (thousandDollarBills) 
		       cout << thousandDollarBills << " one thousand dollar bills, " << endl;

		    // fiveHundredDollarBills
		    for (fiveHundredDollarBills = 0; changeDue >= 500.00; fiveHundredDollarBills++)
		       changeDue -= 500.00;
		    if (fiveHundredDollarBills) 
		       cout << fiveHundredDollarBills << " five hundred dollar bills, " << endl;

		    // hundredDollarBills
		    for (hundredDollarBills = 0; changeDue >= 100.00; hundredDollarBills++)
		       changeDue -= 100.00;
		    if (hundredDollarBills) 
		       cout << hundredDollarBills << " hundred dollar bills, " << endl;

		    // fiftyDollarBills
		    for (fiftyDollarBills = 0; changeDue >= 50.00; fiftyDollarBills++)
		       changeDue -= 50.00;
		    if (fiftyDollarBills) 
		       cout << fiftyDollarBills << " fifty dollar bills, " << endl;

		    // twentyDollarBills
		    for (twentyDollarBills = 0; changeDue >= 20.00; twentyDollarBills++)
		       changeDue -= 20.00;
		    if (twentyDollarBills) 
		       cout << twentyDollarBills << " twenty dollar bills, " << endl;

		    // tenDollarBills
		    for (tenDollarBills = 0; changeDue >= 10.00; tenDollarBills++)
		       changeDue -= 10.00;
		    if (tenDollarBills) 
		       cout << tenDollarBills << " ten dollar bills, " << endl;

		    // fiveDollarBills
		    for (fiveDollarBills = 0; changeDue >= 5.00; fiveDollarBills++)
		       changeDue -= 5.00;
		    if (fiveDollarBills) 
		       cout << fiveDollarBills << " five dollar bills, " << endl;

		    // twoDollarBills
		    for (twoDollarBills = 0; changeDue >= 2.00; twoDollarBills++)
		       changeDue -= 2.00;
		    if (twoDollarBills) 
		       cout << twoDollarBills << " two dollar bills, " << endl;


		    // oneDollarBills
		    for (oneDollarBills = 0; changeDue >= 1.00; oneDollarBills++)
		       changeDue -= 1.00;
		    if (oneDollarBills) 
		       cout << oneDollarBills << " one dollar bills, " << endl;
		    
		    // quarters
		    for (quarters = 0; changeDue >= 0.25; quarters++)
		        changeDue -= 0.25;
		    if (quarters)
		        cout << quarters << " quarters, " << endl;
		    
		    // dimes
		    for (dimes = 0; changeDue >= 0.10; dimes++)
		        changeDue -= 0.10;
		    if (dimes)
		        cout << dimes << " dimes, " << endl;
		    
		    // nickels
		    for (nickels = 0; changeDue >= 0.05; nickels++)
		        changeDue -= 0.05;
		    if (nickels)
		        cout << nickels << " nickels, " << endl;
		    
		    // pennies, just for good measure
		    for (pennies = 0; changeDue > 0.00; pennies++)
		        changeDue -= 0.01;
		    if (pennies)
		        cout << pennies << " pennies.\n\n" << endl;
		} else {
		    // They must have given exact change
		    cout << "Thanks for using exact change!\n" << endl;
		}
    }
    
    return 0;
}
Topic archived. No new replies allowed.