I am so new at function I am having a great deal of trouble I can write the program and it comes out exactly as it is supposed to so how can I turn this into a function
Code:#include <iostream> #include <iomanip> #include <string> #include <cmath> using namespace std; int main( ) { const float yearly_int_rate = 0.053; const float quarterly_int_rate = (0.053/4.0); double balance; double new_balance; double interest_earned; int quarter; double first_qt_interest; double second_qt_interest; double third_qt_interest; double fourth_qt_interest; double first_qt_balance; double second_qt_balance; double third_qt_balance; double fourth_qt_balance; interest_earned = 0; new_balance = 0; balance = 0; quarter = 0; first_qt_interest = 0; second_qt_interest = 0; third_qt_interest = 0; fourth_qt_interest = 0; first_qt_balance = 0; second_qt_balance = 0; third_qt_balance = 0; fourth_qt_balance = 0; cout << "Enter the account balance and press the Enter key ./n " << endl; cin >> balance; first_qt_interest = balance * quarterly_int_rate; first_qt_balance = balance + first_qt_interest; second_qt_interest = first_qt_balance * quarterly_int_rate; second_qt_balance = first_qt_balance + second_qt_interest; third_qt_interest = second_qt_balance * quarterly_int_rate; third_qt_balance = second_qt_balance + third_qt_interest; fourth_qt_interest = third_qt_balance * quarterly_int_rate; fourth_qt_balance = third_qt_balance + fourth_qt_interest; cout << fixed << showpoint; cout << setprecision(2); cout << "Quarter " << "Balance " << "Interest Earned " << "New Balance " << endl; cout << setw(4) << "1" << setw(9) << "$" << balance << setw(9) << "$" << first_qt_interest << setw(10) << "$" << first_qt_balance << endl; cout << setw(4) << "2" << setw(9) << "$" << first_qt_balance << setw (9) << "$" << second_qt_interest << setw(10) << "$" << second_qt_balance << endl; cout << setw(4) << "3" << setw(9) << "$" << second_qt_balance << setw(9) << "$" << third_qt_interest << setw(10) << "$" << third_qt_balance << endl; cout << setw(4) << "4" << setw(9) << "$" <<third_qt_balance << setw(9)<< "$" << fourth_qt_interest << setw(10) << "$" << fourth_qt_balance << endl; system("pause"); return 0; }



LinkBack URL
About LinkBacks




