if/else/logic problems & compilation errors c2181 & c1075

Hello, I am a beginning C++ student who needs help with a program.
I'm trying to make a program where the user inputs the price of an item they are buying, pays for it with a larger number of cash, where then the program is supposed to issue change back to the customer(dollars, quarters, pennies, etc..). However, if the customer doesn't receive one type of currency (i.e. dimes), then I don't want the program to output "Dimes: 0." This is the idea I'm getting at:

Amount to be lent: 45000
Amount offered: 100000
Change due: 55000

Change includes this many ten thousand dollar bills: 5
Change includes this many five thousand dollar bills: 1

I'm not going to do it with big bills like the example does, I'm just using dollar bills and change. Whenever I compile it though, I receive 2 errors:

C2181 - illegal else without matching if
C1075 - end of file found before the left token at 'filename(linenumber)' was matched


This is the code I have so far:


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
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
	int dollars,quarters,dimes,nickels,pennies;
	double due,payment,change;


	// Get the amount due
	cout << "Please enter the price:\n";
	cin >> due;

	// Check the amount due for problems
	while (due <= 0.01) {
		// Somebody entered zero or less, probably trying to get some free money
		cout << "Sorry cheapskate, you must spend at least $0.01\n\n";

		// Ask again for the real price
		cout << "Please enter the ACTUAL price:\n";
		cin >> due;
		cout << endl;
	}

	// Get the payment amount
	cout << "Please provide payment amount (using numbers only):\n";
	cin >> payment;

	// Check payment amount for problems
	while (payment < due) {
		// Somebody is trying to pay less than what's due
		// but we're not accepting ANY money unless we get it all at once
		cout << "No, you owe $" << due << ", not $" << payment << ".\n\n";
		cout << endl << "Please provide FULL payment:\n";
		cin >> payment;
	}



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

        // dollars
        for (dollars = 0; change >= 1.00; dollars++){
           change -= 1.00;
           //cout << dollars << " dollars, ";
        
        // quarters
        for (quarters = 0; change >= 0.25; quarters++){
            change -= 0.25;
            //cout << quarters << " quarters, ";
        
        // dimes
        for (dimes = 0; change >= 0.10; dimes++){
            change -= 0.10;
            //cout << dimes << " dimes, ";
        
        // nickels
        for (nickels = 0; change >= 0.05; nickels++){
            change -= 0.05;
            //cout << nickels << " nickels, ";
        
        // pennies, just for good measure
        for (pennies = 0; change > 0.00; pennies++){
            change -= 0.01;
            //cout << pennies << " pennies.\n\n";
        

        for (;change > 0;){
           cout << dollars << " dollars, ";
           cout << quarters << " quarters, ";
           cout << dimes << " dimes, ";
           cout << nickels << " nickels, ";
           cout << pennies << " pennies.\n\n";

} 
        else {
        // They must have given exact change
        cout << "Thanks for using exact change!\n";




 }

  }

   }

    }

     }

      }


	return 0;


}



Any comments or advice would be helpful. Thanks!
Use proper indentation and the problem should be revealed.
You are forgetting to close each for loop. Do this:

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
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
    int dollars,quarters,dimes,nickels,pennies;
    double due,payment,change;

    // Get the amount due
    cout << "Please enter the price:\n";
    cin >> due;

    // Check the amount due for problems
    while (due <= 0.01) {
        // Somebody entered zero or less, probably trying to get some free money
        cout << "Sorry cheapskate, you must spend at least $0.01\n\n";

        // Ask again for the real price
        cout << "Please enter the ACTUAL price:\n";
        cin >> due;
        cout << endl;
    }

    // Get the payment amount
    cout << "Please provide payment amount (using numbers only):\n";
    cin >> payment;

    // Check payment amount for problems
    while (payment < due) {
        // Somebody is trying to pay less than what's due
        // but we're not accepting ANY money unless we get it all at once
        cout << "No, you owe $" << due << ", not $" << payment << ".\n\n";
        cout << endl << "Please provide FULL payment:\n";
        cin >> payment;
    }

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

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