Same value for all inputs

I'm supposed to write a program for a loan calculator. I know there are other errors in the code (like option 5 and 6 are not set up yet), but I'm trying to figure out why it isn't recognizing the values for principal, annual interest, number of months and monthly payment separately. It enters the same value, despite which number I choose, into all options.




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

#include <iostream>
#include <cmath>

using namespace std;

#define MR 
#define PR	1
#define YR	2
#define NM	3
#define MP	4
#define CP	5
#define CM	6
#define quit 7 


int principal()
{
cout << "Enter principal amount: ";
int principal_amount; cin >> principal_amount;
return principal_amount;
}

int annual_interest()
{
cout << "Enter annual interest: ";
int interest; cin >> interest;
return interest;
}

int number_of_months()
{
cout << "Enter number of months: ";
int months; cin >> months;
return months;
}

int monthly_payment()
{
cout << "Enter monthly payment: ";
int payment; cin >> payment;
return payment;
}


	int get_choice(int choice_num)
{

	cout << "LOAN CALCULATOR" << endl;
	cout << "---------------" << endl;

	cout << "               " << endl;
	cout << PR <<". Set principal		: $" << choice_num  << endl;
	cout << YR <<". Set annual interest		: " << choice_num << "%" << endl;
	cout << NM <<". Set number of months		: " << choice_num << endl;
	cout << MP <<". Set monthly payment		: $" << choice_num << endl;
	cout << "                             " << endl;
	cout << "   5. Calculate principal" << endl;
	cout << "   6. Calculate monthly payment" << endl;
	cout << "                             " << endl;
	cout << "   7. Exit" << endl;
	cout << "                             " << endl;
	
cout <<  "Enter Choice: " << endl;
int choice; cin  >> choice;

return choice;
}



void calculate_principal(int principal)
{

int result;
cout << "Result: " << result << endl;
}



  int  main()
  {
    int choice  =  0;
    bool done  =  false;

    while( ! done )
    {
      switch( get_choice(choice) )
      {
        case  PR  :  choice = principal();
                                    break;
        case  YR  :  choice = annual_interest();
                                    break;
        case  NM  :  choice = number_of_months();
                                    break;
        case  MP  :  choice = monthly_payment();
                                    break;
		case  CP  :  calculate_principal(choice);
									break;
        case  quit        :  done  =  true;
                                    break;
		default  :
           cout  <<  "*** Invalid choice ***"  <<  endl  <<  endl;
           break;
      }
    }

    return  0;
  }





You have a logic problem in monthly_payment, it will display the same value for everything
I don't see how monthly_payment is set up any differently than the other first three options. Anyway, I'm trying to figure out where the logic problem is happening. An indication to the line would be nice.
Your bad indentation threw Bazzy off -- the problem is in get_choice(), lines 46-68.

For each option, you are displaying the same value. What does choice_num (and choice) have to do with with your principal, interest, number of months, and monthly payment?

BTW, I don't recommend using integers for your monies. When it comes time to calculate things like the principle you will want to have non-integer values, so that things like division work correctly.
Topic archived. No new replies allowed.