Creating a table?

Hello, everyone! This is my first post, and I really thank anyone in advance that can help me. I'm obviously a beginner, and am trying to figure out why the else cout << "Please insert a number from 1-20."; won't show up.

Also, the interestRate should be displayed in my tables as (interest - .10) at the first table, (interest) in the second, and (interest + .10) in the third. I don't know how to do this without sacrificing i++ in the table. Sorry if I'm not making sense.

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

int main() {
       int years;
       double rate, initialDeposit, interestRate, begBalance, balance;
       double interest = 0;
       char choice;
       bool test=false;
       
       while (!test) {
       
             cout << "Initial deposit? ";
             cin >> initialDeposit;
             cout << "Interest rate? ";
             cin >> rate;
             interestRate = (rate -.10);
             
             do{
                 cout << "Number of years? ";
                 cin >> years;
             }while (years < 1 || years > 20);
             
             if (years <= 10) years = 10;
                 else if (years <= 20) years = 20;
                      else cout << "Please insert a number from 1-20.";
                           
                 
             
             cout << setprecision(2) << fixed;
             
             for (int i = 1; i <= 3 ; i++) {
                 
                 cout << endl;
                 cout  << "Rate > " << interestRate << "%" << endl << endl;
                 cout << setw(16) << "Beginning" << setw(27) << "Ending"<<endl;
                 cout << "Year" << setw(10) << "Balance" << setw(16) << "Interest" << setw(14) << "Balance"<<endl;
                 balance = initialDeposit;
                 
                 for (int j = 1; j <= years; j++){
                     begBalance = balance;
                     interest = begBalance * (interestRate / 100);
                     balance = balance + interest;
                     interestRate = interestRate + .10;
                 
                     cout << endl << setw(5) << j << setw(10)<< begBalance << setw(15) << interest << setw(15) << balance;
                 
                 }
                 
             cout << endl << endl;                 
             }
             
             cout << "Would you like to try again? (Y/N)? ";
             cin >> choice;
             if (choice == 'n' || choice == 'N') test = true;
      }
      system("PAUSE");
    return 0;
}
Last edited on
Sorry for the bump, but I edited my post with a new code. Hopefully someone can 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
#include <iostream>
using namespace std;
#include <iomanip>

int main() {
       int years;
       double rate, initialDeposit, interestRate, begBalance, balance;
       double interest = 0;
       char choice;
       bool test=false;

       while (!test) {

             cout << "Initial deposit? ";
             cin >> initialDeposit;
             cout << "Interest rate? ";
             cin >> rate;
             interestRate = (rate -.10);

             do{
                 cout << "Number of years? ";
                 cin >> years;

             //// **** moved here **** ////////
             if (years <= 10) years = 10;
                 else if (years <= 20) years = 20;
                      else cout << "Please insert a number from 1-20.";
             ///////////////////////////////////////

             }while (years < 1 || years > 20);

             /*
             if (years <= 10) years = 10;
                 else if (years <= 20) years = 20;
                      else cout << "Please insert a number from 1-20.";
             */


             cout << setprecision(2) << fixed;

             for (int i = 1; i <= 3 ; i++) {

                 cout << endl;
                 cout  << "Rate > " << interestRate << "%" << endl << endl;
                 cout << setw(16) << "Beginning" << setw(27) << "Ending"<<endl;
                 cout << "Year" << setw(10) << "Balance" << setw(16) << "Interest" << setw(14) << "Balance"<<endl;
                 balance = initialDeposit;

                 for (int j = 1; j <= years; j++){
                     begBalance = balance;
                     interest = begBalance * (interestRate / 100);
                     balance = balance + interest;

                     // interestRate = interestRate + .10;

                     cout << endl << setw(5) << j << setw(10)<< begBalance << setw(15) << interest << setw(15) << balance;

                 }

                 interestRate = interestRate + .10; // *** moved here

             cout << endl << endl;
             }

             cout << "Would you like to try again? (Y/N)? ";
             cin >> choice;
             if (choice == 'n' || choice == 'N') test = true;
      }
}
Thank you! You saved my butt!
Topic archived. No new replies allowed.