nevermind: ignore arrays problem - quick question

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2008
Posts: 21
Reputation: WonderWomen204 is an unknown quantity at this point 
Solved Threads: 0
WonderWomen204 WonderWomen204 is offline Offline
Newbie Poster

Arrays problem; quick question

 
0
  #1
Apr 18th, 2008
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
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. double loanAmounts[10];
  9. int numMonths[10];
  10. string keepGoing;
  11. int counter = 0;
  12. double payment = 0;
  13. double totalMonthlyPayment = 0;
  14.  
  15. do
  16. {
  17. cout << "Please enter a loan amount: ";
  18. cin >> loanAmounts[counter];
  19. cout << "Please enter the number of months: ";
  20. cin >> numMonths[counter];
  21. payment = loanAmounts[counter] / numMonths[counter];
  22. totalMonthlyPayment = totalMonthlyPayment + payment;
  23. counter++;
  24.  
  25. cout << "Continue (yes/no) ";
  26. cin >> keepGoing;
  27. }
  28. while ((keepGoing == "yes") || (keepGoing == "YES"));
  29.  
  30. cout << "**********************" << endl;
  31.  
  32. for (int x = 0; x < counter; x++)
  33. {
  34. double payment = (double)loanAmounts[x] / (double)numMonths[x];
  35. int loanNumber = x + 1;
  36. [B]int totalLoans = loanNumber + loanNumber + 1;[/B]
  37. cout << "There are " << totalLoans << " loans. " << endl;
  38. cout << "Loan " << (x+1) << " for $ " << loanAmounts[x];
  39. cout << " for " << numMonths[x] << " months has a payment ";
  40. cout << " of " << payment << " per month " << endl;
  41. }
  42. cout << "TOTAL MONTHLY PAYMENT: " << totalMonthlyPayment << endl;
  43. }
Last edited by Ancient Dragon; Apr 18th, 2008 at 12:35 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 21
Reputation: WonderWomen204 is an unknown quantity at this point 
Solved Threads: 0
WonderWomen204 WonderWomen204 is offline Offline
Newbie Poster

nevermind: ignore arrays problem - quick question

 
0
  #2
Apr 18th, 2008
hey everyone. I was able to figure the problem out . Therefore it can be marked solved. Thanks : ).
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC