|
Using a while loop and a nested if statement.
When you went off to college your parents gave you a credit card. To try out the credit card, you charged some new clothes, a new laptop, and a printer. Your parents gave you enough money to pay that bill, but you used the money for something else. Winter Break came, and you took a trip to Florida. All of your expenses went on the charge card. Then came the Spring Break skiing weekend in Aspen; you needed a new skiing outfit. Who knew it would be so expensive? Staying in the lodge, equipment rentals, and those expensive restaurants all went on that credit card. You continued to use the credit card. You are almost ready to graduate, and your parents asked if you ever use that emergency credit card that you got your freshman year. Suddenly you realize that you are in debt! You have only been paying the minimum amount each month.
Write a program that will calculate the number of months it will take you to pay off the credit card debt if you quit using the credit card today.
Input:
-The amount that you owe (the balance) -The yearly interest rate of the credit card -The amount that you think you can pay each month
Output:
-A phrase before each input statement so that you will know which value to enter.
-The payment number and the remaining balance for each payment until the debt is paid off. Use endl so that it will be easy to read on the screen.
-A message if it will take less than a year, more than two years, or more than five years to pay off the debt.
Calculations:
-The yearly interest rate divided by 12 will give the monthly interest rate. For each month, add the monthly interest rate times the current balance to the current balance and subtract the monthly payment.
Ch Code:
#include <iostream.h> main ( ) { float balance, YRate, MRate, payment; int j,i; cls; cout << "Enter the amount you owe on this credit card: " << endl; cin >> balance; cout << "Enter yearly interest rate on credit card: " << endl; cin >> YRate; cout << "Enter the amount you can afford to pay each month: " << endl; cin >> payment; MRate = YRate/12; i = 0; j = 1; while(j) { balance = ((MRate * balance)+ balance) - payment; If (balance > 0) i = i + 1; else j = 0; } getchar(); printf("number of months to payoff credit card is \n"); printf(i);
}
|