Looping program back to the beginning

I have created a mortgage amorization program for school. After fixing over 100 errors I have got the program to work. However, I have tried to no avail to loop the program back to the beginning using a bool loop, a question, and within the indicator part of the program. The rest of the program works. Can somone look at my code and tell me how to code the program to loop back to the beginning and where the loop needs to be placed, thanks.

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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

#include "math.h"
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

using std::cout;
using std::endl;
using std::cin;

//mortgage class//
class Mortgage

{
	public: 
	void header(); 
	void enterprinc();
	double princ; 
	double anInt; 
	int yrs; 
};

//define function//

void Mortgage::header() 
{

	cout << "Welcome to Smith's Amortization Calculator\n\n";
	cout << endl;
	cout << "Week 3 Individual Assignment C++ Mortgage Amortization Calculator\n\n";
	cout << endl;

}

void Mortgage::enterprinc()
{

	cout << endl;
	cout << "Enter the amount The Mortgage Amount:$"; 
	cin >> princ;

}

//main function//
int main ()
{

Mortgage mortgageTotal;

	double princ = 0; 
	double anInt [4]= {0, 5.35, 5.5, 5.75,}; 
	double yrs [4]= {0, 7, 15, 30,}; 
	double pmt = 0; 
	double intPd = 0; 
	double bal = 0; 
	double amtPd = 0; 
	double check(int min, int max);
	int NOP = 0; 
	int Mnth = 0; 
	int SL = 0; 
	char indicator = ('A' ,'a','R','r','D','d'); 
    int select;  

//Begin Loop
{
	mortgageTotal.header ();
	mortgageTotal.enterprinc ();

		cout<< "Please Enter Your Selection!"<< endl;
		cout<< "Press A to make selection for term of mortgage and interest rate"<<endl;
		cin >> indicator;

			if (indicator == 'A','a')
			{

				cout << "Please select your Terms and Rates from the following choices: " << endl;
				cout << "1. 7 years at 5.35%" << endl;
				cout << "2. 15 years at 5.5%" << endl;
				cout << "3. 30 years at 5.75%" << endl;
				cout << endl;
				cout << "What is your selection:";

					select = 0;
					cin >> select;
					cout << endl << endl << endl;
						switch (select)
			{

				case 0: cout << endl; 
				break;
				case 1:
					yrs[2] = 7;
					anInt[2] = 5.35; 
					cout << "You have selected a 7 year mortgage at 5.35% interest." << endl; 
					break;

				case 2: 
					yrs[3] = 15;
					anInt[3]= 5.50; 
					cout << "You have selected 15 year mortgage at 5.50 interest%" << endl; 
					break;

				case 3: 
					yrs[4] = 30;
					anInt[4] = 5.75; 
					cout << "You have selected a 30 year mortgage at 5.75% interest" << endl; 
					break;

				default: 
					cout << "Invalid Line Number" << endl;
					if ((select < 1)|| (select > 3))

					{ 
						system("cls");
						cout << "Your choice is invalid, please enter a valid choice!!!";
						system("PAUSE");
						system("cls");
						return main();
					}
			}
			}
				
//Formulas//
double pmt = (mortgageTotal.princ*((anInt[select]/1200)/(1 - pow((1+(anInt[select]/1200)),-1*(yrs[select]*12))))); //  notice the variable in the brackets that i added.

	cout << "Your Monthly Payment is: $" << pmt << "\n";
	cout << endl;

double NOP = yrs [select] * 12;
	SL = 0;
		for (Mnth = 1; Mnth <= NOP; ++Mnth)
		{

	intPd = mortgageTotal.princ * (anInt[select] / 1200);   
	amtPd = pmt - intPd;
	bal = mortgageTotal.princ - amtPd;
		if (bal < 0)bal = 0;
			mortgageTotal.princ = bal;

			if (SL == 0)
			{
				cout << "Balance of Loan" << "\t\t\tAmount of Interest Paid" << endl;
			}

				cout << setprecision(2) << fixed << "$" << setw(5) << bal << "\t\t\t\t$"<< setw(5) << intPd << endl;
				++SL;

//Allows user to decide whether or not to continue//

	if (SL == 12)
	{
		cout << "Would you like to continue the amoritization or quit the program?\n";
		cout << endl;
		cout << "Enter 'R' to see the remainder or 'D' for done.\n";
		cin >> indicator;

			if 
				(indicator == 'R','r')SL = 0;

					else

			if

				(indicator == 'D','d')
				cout << endl;

	}

}

}

return 0;
}
I'd use a do..while loop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cctype>
#include <iostream>
using namespace std;

int main()
  {
  bool done = false;

  do {

    if (tolower( indicator ) == 'd')
      {
      cout << endl;
      done = true;
      }

  } while (!done);

  cout << "Good bye.\n";
  return 0;
  }

Hope this helps.
Thanks for your tip. Your example gave me an idea. I added a bool statement to the loop and added some new lines of code and deleted some existing lines of code. I am posting the completed program that meets the programs requirments because I struggles so much with this assignment that I thought maybe my example would help another student with ideas. When I first started I had over 100 errors and then I could not loop the program back to the beginning, but after several days and a lot of stress, I finally obtained my goal. Thank you very much.

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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

#include "math.h"
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

using std::cout;
using std::endl;
using std::cin;

//mortgage class//
class Mortgage

{
	public: 
	void header(); 
	void enterprinc();
	double princ; 
	double anInt; 
	int yrs; 
};

//define function//

void Mortgage::header() 
{

	cout << "Welcome to Smith's Amortization Calculator\n\n";
	cout << endl;
	cout << "Week 3 Individual Assignment C++ Mortgage Amortization Calculator\n\n";
	cout << endl;

}

void Mortgage::enterprinc()
{

	cout << endl;
	cout << "Enter the amount The Mortgage Amount:$"; 
	cin >> princ;

}

//main function//
int main ()
{

Mortgage mortgageTotal;

	double princ = 0; 
	double anInt [4]= {0, 5.35, 5.5, 5.75,}; 
	double yrs [4]= {0, 7, 15, 30,}; 
	double pmt = 0; 
	double intPd = 0; 
	double bal = 0; 
	double amtPd = 0; 
	double check(int min, int max);
	int NOP = 0; 
	int Mnth = 0; 
	int SL = 0; 
	char indicator = ('A' ,'a','R','r','D','d'); 
    int select;  

//Begin Loop

bool finished = false;   
while( !finished )      
{
	mortgageTotal.header ();
	mortgageTotal.enterprinc ();

		cout<< "Press 'A' to make selection for term of mortgage and interest rate"<<endl;
		cin >> indicator;

			if (indicator == 'A','a')
			{

				cout << "Please select your Terms and Rates from the following choices: " << endl;
				cout << "1. 7 years at 5.35%" << endl;
				cout << "2. 15 years at 5.5%" << endl;
				cout << "3. 30 years at 5.75%" << endl;
				cout << endl;
				cout << "What is your selection:";

					select = 0;
					cin >> select;
					cout << endl << endl << endl;
						switch (select)
			{

				case 0: cout << endl; 
				break;
				case 1:
					yrs[2] = 7;
					anInt[2] = 5.35; 
					cout << "You have selected a 7 year mortgage at 5.35% interest." << endl; 
					break;

				case 2: 
					yrs[3] = 15;
					anInt[3]= 5.50; 
					cout << "You have selected 15 year mortgage at 5.50 interest%" << endl; 
					break;

				case 3: 
					yrs[4] = 30;
					anInt[4] = 5.75; 
					cout << "You have selected a 30 year mortgage at 5.75% interest" << endl; 
					break;

				default: 
					cout << "Invalid Line Number" << endl;
					if ((select < 1)|| (select > 3))

					{ 
						system("cls");
						cout << "Your choice is invalid, please enter a valid choice!!!";
						system("PAUSE");
						system("cls");
						return main();
					}
			}
			}
				
//Formulas//
double pmt = (mortgageTotal.princ*((anInt[select]/1200)/(1 - pow((1+(anInt[select]/1200)),-1*(yrs[select]*12))))); //  notice the variable in the brackets that i added.

	cout << "Your Monthly Payment is: $" << pmt << "\n";
	cout << endl;

double NOP = yrs [select] * 12;
	SL = 0;
		for (Mnth = 1; Mnth <= NOP; ++Mnth)
		{

	intPd = mortgageTotal.princ * (anInt[select] / 1200);   
	amtPd = pmt - intPd;
	bal = mortgageTotal.princ - amtPd;
		if (bal < 0)bal = 0;
			mortgageTotal.princ = bal;

			if (SL == 0)
			{
				cout << "Balance of Loan" << "\t\t\tAmount of Interest Paid" << endl;
			}

				cout << setprecision(2) << fixed << "$" << setw(5) << bal << "\t\t\t\t$"<< setw(5) << intPd << endl;
				++SL;

//Allows user to continue amortization//

	if (SL == 12)
	{
		cout << "Enter 'R' to see the remainder or 'D' when mortgage amortization is finished.\n";
		cin >> indicator;

			if 
				(indicator == 'R','r')SL = 0;

					else

			if

				(indicator == 'D','d')
				cout << endl;

	}

}
//loops program back to the beginning//
char tempChar;    
	cout << "Do you wish to loop through the code again? [Y/N]: ";    
	cin >> tempChar; 

		if( tempChar == 'N' || tempChar == 'n' )      
			finished = true;

}

return 0;
}
Topic archived. No new replies allowed.