simple loan program not working right

i have this assignment due for school to write a simple program to calculate loans. it compiles and runs in dev c ++ but does not in cygwin, which my teacher uses to grade it. it does not loop over and over like its supposed to. it says id returned 1 exit status and has a warning... no newline at the end of file. what do i need to do to get this working like its supposed to? here is my code.


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


# include <iostream>
# include <iomanip>
# include <cmath>

using namespace std;

int main ()
{
 
 double loanAmountA;
 double annualRate;
 double paymentAmount;
 double amountInterest;
 double interestCharged;
 double ratePeriod;
 double balanceAfter; 
 double balance;
 int paymentsPerYear;
 int totalPayments;
 int loanCount = 0;
 int paymentCount = 1;
 bool anotherLoan = true;
 char response;
	
      while (anotherLoan == true)
	{
	
     cout<<"Enter amount of loan A:$ ";
	 cin>>loanAmountA;
	 cout<<endl;
	 cout<<"Enter annual percentage rate (APR): "<<"%";
	 cin>>annualRate;
	 cout<<endl;
	 cout<<"Enter the number of payments per year: ";
	 cin>>paymentsPerYear;
	 cout<<endl;
	 cout<<"Enter the total number of payments: ";
	 cin>>totalPayments;
	 cout<<endl;
     cout<<"Payment      Payment      Amount      Amount to      Balance after";
	 cout<<endl;
	 cout<<"Number       Amount       Interest    Principal       This Payment";
	 cout<<endl;
	 
	
	 
	 cin.ignore(80,'\n');
	 
	 
            while (paymentCount <=totalPayments)
            {
    
             amountInterest = annualRate / 100;
             ratePeriod = amountInterest / totalPayments;
             paymentAmount = (loanAmountA + (amountInterest * loanAmountA))/totalPayments;         	      
	         balance = (paymentAmount * totalPayments) - (paymentAmount * (paymentCount -1 ));	  
             interestCharged = ratePeriod * balance;                        
             balanceAfter = balance - paymentAmount;
       	  
	          if (paymentCount == totalPayments) 
              {
    
                balanceAfter = 0;
                paymentAmount = balance;
    
              }  
         
         
              cout<<left<<setprecision(0)<<setw(3)<<paymentCount<<"          ";
              cout<<setw(13)<<left<<fixed<<setprecision(2)<<paymentAmount;
              cout<<setw(12)<<left<<fixed<<setprecision(2)<<interestCharged;
              cout<<setw(16)<<left<<fixed<<setprecision(2)<<balance;
              cout<<setw(13)<<left<<fixed<<setprecision(2)<<balanceAfter;
         
       
             if (paymentCount % 12 == 0)
             {
                 cout<<endl;
                 cout<<"Hit <Enter> to continue: "<<endl;
                 cin.ignore(80,'\n');
                 cin.get();
             }
    
              paymentCount++;
         
              cout<<endl;
    
       }
	 
	 
	 
	 cout<<"Would you like to calculate another loan? y/n and <enter>";
	 cin>>response;
	 
     loanCount +1;
     
     if (response == 'n') 
	 {
	
     anotherLoan = false;
	 cout<<endl<<endl;
     cout<<"There were: " <<loanCount<< " loans processed.";
     cout<<endl<<endl;
     cin.get();
    
     }
	
    
    }
	
 return 0;
 
}
As for the warning take a look at line 97. That line has no purpose currently -- you're just taking loanCount, adding 1, then discarding the result (the sum isn't getting stored anywhere).

You probably meant to use the += operator.


As for why it's not working on Cygwin, I haven't the foggiest. It's compiling and running fine with GCC on my machine. I don't see anything that would cause compiling to fail or the program to exit abnormally.
What Disch said about line 97 is correct, but "no newline at the end of file" means it wants you to scroll down to the bottom and hit "enter" so the last thing in the code is an empty line.
line 104 is the purpose of line 97 and i did hit enter at the bottom of the code. I will try it in the lab at school tomorrow thanks for the help
Line 97 as you have it there doesn't do anything, it's just a value. It's like writing
5;
If you want to increase loanCount by 1, you need to say
loanCount += 1; or
loanCount = loanCount + 1;or
loanCount++;
Last edited on
Topic archived. No new replies allowed.