In: Computer Science
Cpp challenge
Description
The purpose of this challenge is to use various flow control structures. This challenge uses techniques for displaying formatted output, simulating a payment structure for paying off outstanding debt such as a credit card or any kind of interest-bearing loan.
Requirements
cout << setw(5) << months << setw(10) << start_bal ... (of course, you can't actually use ellipses in the code. That's just an indicator that you can continue with whatever data and formatting you need)
Do Not Use
You may not use the break statement to terminate any loops
Sample Interaction / Output
What is the outstanding balance? 2000 What is the APR? 24 How much do you pay every month? 125 The table shows how long it will take to pay: Month Start Interest Monthly End 1 2000.00 40.00 125.00 1915.00 2 1915.00 38.30 125.00 1828.30 3 1828.30 36.57 125.00 1739.87 4 1739.87 34.80 125.00 1649.66 5 1649.66 32.99 125.00 1557.66 6 1557.66 31.15 125.00 1463.81 7 1463.81 29.28 125.00 1368.09 8 1368.09 27.36 125.00 1270.45 9 1270.45 25.41 125.00 1170.86 10 1170.86 23.42 125.00 1069.27 11 1069.27 21.39 125.00 965.66 12 965.66 19.31 125.00 859.97 13 859.97 17.20 125.00 752.17 14 752.17 15.04 125.00 642.22 15 642.22 12.84 125.00 530.06 16 530.06 10.60 125.00 415.66 17 415.66 8.31 125.00 298.97 18 298.97 5.98 125.00 179.95 19 179.95 3.60 125.00 58.55 20 58.55 1.17 125.00 -65.28
If you have any doubts, please give me comment...
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
double balance, monthly, apr, apr_monthly, start_bal, interest, end_bal;
int months;
cout<<"What is the outstanding balance? ";
cin>>balance;
cout<<"What is the APR? ";
cin>>apr;
cout<<"How much do you pay every month? ";
cin>>monthly;
start_bal = balance;
months = 1;
cout<<"\nThe table shows how long it will take to pay:\n"<<endl;
cout<<setprecision(2)<<fixed;
cout<<setw(5)<<"Month"<<setw(10)<<"Start"<<setw(10)<<"Interest"<<setw(10)<<"Monthly"<<setw(10)<<"End"<<endl;
while(start_bal>0){
apr_monthly = (apr/12.0)/100;
interest = start_bal * apr_monthly;
end_bal = start_bal + interest - monthly;
cout<<setw(5)<<months<<setw(10)<<start_bal<<setw(10) <<interest<<setw(10)<<monthly<<setw(10)<<end_bal<<endl;
start_bal = end_bal;
months++;
}
return 0;
}