Hey there. It's Erinn and I just have a quick question about my assignment that I am working on. I have everything right except for one part...don't u hate that...lol. Anyway, here is the code and assignment below. Sorry there is no code, but it's been a long day and I'm tired.
The assignment is: Write a program which asks the user for a series of pairs of values: loanAmount and numMonths. There might be as many as 10 of these. After getting all of the input, print a list of the loans, the number of months, and the payment per month (no interest charged). For example:
Please enter a loan amount: 1000
Please enter the number of months: 10
Continue (yes/no)? yes
Please enter a loan amount: 999
Please enter the number of months: 30
Continue (yes/no)? yes
Please enter a loan amount: 1234
Please enter the number of months: 5
Continue (yes/no)? no
************************* <<- YES PRINT THESE ASTERISKS
There are 3 loans.
Loan 1 for $1000 for 10 months has a payment of $100 per month
Loan 2 for $999 for 30 months has a payment of $33.3 per month
Loan 1 for $1234 for 5 months has a payment of $246.8 per month
TOTAL MONTHLY PAYMENT: $380.1
Here is the coding I have. The only question I have is on the part where it says, "There are 3 loans." The part of the code I need help with is in bold. Again, everything I have works and is fine except how to do I properly write that calculation and do I place it there or before the while? I get three when I do this program, but when I just for the heck of it try additional ones other than 3, i just get 3. For example, the assignment says only three, but I try four, and I only get three and not four. Could someone help me with this part? Thanks :)
#include <iostream>
#include <string>
using namespace std;
int main()
{
double loanAmounts[10];
int numMonths[10];
string keepGoing;
int counter = 0;
double payment = 0;
double totalMonthlyPayment = 0;
do
{
cout << "Please enter a loan amount: ";
cin >> loanAmounts[counter];
cout << "Please enter the number of months: ";
cin >> numMonths[counter];
payment = loanAmounts[counter] / numMonths[counter];
totalMonthlyPayment = totalMonthlyPayment + payment;
counter++;
cout << "Continue (yes/no) ";
cin >> keepGoing;
}
while ((keepGoing == "yes") || (keepGoing == "YES"));
cout << "**********************" << endl;
for (int x = 0; x < counter; x++)
{
double payment = (double)loanAmounts[x] / (double)numMonths[x];
int loanNumber = x + 1;
[B]int totalLoans = loanNumber + loanNumber + 1;[/B]
cout << "There are " << totalLoans << " loans. " << endl;
cout << "Loan " << (x+1) << " for $ " << loanAmounts[x];
cout << " for " << numMonths[x] << " months has a payment ";
cout << " of " << payment << " per month " << endl;
}
cout << "TOTAL MONTHLY PAYMENT: " << totalMonthlyPayment << endl;
}