Read the lab requests and fix my mistakes
#include <iostream> #include <cmath> #include <String> #include <iomanip> #include <fstream> using namespace std; ifstream infile; ofstream outfile; int number_of_shares; int number_of_years; //so that there are spaces in name char with 250 length or 250 chars. string user_name; string answer; double price; double percent_commission; double anual_rate; char A, B, C, D, E; char selection; char ans; int base; int anual_growth; int monthly_contribution; int num_years; int begining_value; int mortgage_term; int mortgage_principle; double mortgage_rate; double mortgate_monthly_rate; void Investment_projection(); void Retirement_planning(); void Mortgage(); int main() { cout << "Hello," << endl << "What is your name? "; //For spaces in name get line. getline(cin, user_name); cout << " " << endl; do { cout << "Please Select a service:" << endl; cout << "A: Investment projection." << endl; cout << "B: Retirement planning." << endl; cout << "C: Mortgage." << endl; cout << "D: College fund." << endl; cout << "E: Exit." << endl; cin >> selection; switch (selection) { case 'a': case 'A': Investment_projection(); cout << "Do you want another transaction?" << endl << "Please Enter Y/N "; cin >> ans; break; case 'b': case 'B': Retirement_planning(); cout << "Do you want another transaction?" << endl << "Please Enter Y/N"; cin >> ans; break; case 'c': case 'C': Mortgage(); cout << "Do you want another transaction?" << endl << "Please Enter Y/N"; cin >> ans; break; case 'd': case 'D': cout << "service coming soon." << endl; cout << "Do you want another transaction?" << endl << "Please Enter Y/N"; cin >> ans; break; case 'e': case 'E': ans = 'N'; cout << "thanks."; break; default: cout << "invalid selection.\n"; cout << "Do you want another transaction?" << endl << "Please Enter Y/N"; cin >> ans; break; } } while (ans == 'Y' || ans == 'y'); cout << endl << "Have a nice Day!!"; return 0; } //The investment projection Part A. void Investment_projection() { cout << "How many shares you bought, " << user_name << "? "; cin >> number_of_shares; cout << "What was the price per share? "; cin >> price; cout << "Percent of commission for broker? "; cin >> percent_commission; cout << "Average annual return percentage? "; cin >> anual_rate; cout << "How many years you will hold the stock? "; cin >> number_of_years; cout << " " << endl; cout << "The amount paid for the stock alone is: "; //Multiples the number of shares times the price to get the total money. double total = number_of_shares * price; cout << total << endl; cout << "The amount of the commission is: "; //calculates the commission by multiplying the total money and the percent commission. double commission = (percent_commission / 100.0) * total; cout << commission << endl; //adds the commission to the total to get the total price paid. cout << "The total amount of paid: "; cout << total + commission << endl; cout << "After " << number_of_years << " years, shares will be worth: "; double time = number_of_years; //Calculates the FV(final value) after X years, uses the equation FV=P(1+i)^t double finalmoney = total * pow((1 + (anual_rate / 100)), time); cout << finalmoney << endl; cout << " " << endl; //Asks for the receipt. cout << "Would you like a receipt? " << endl << "Please type yes or no. "; cin >> answer; cout << " " << endl; if (answer == "yes") { cout << "Name: " << user_name << endl; cout << "------------------------------------------" << endl; cout << "Total Stock: " << setw(17) << "$ " << setw(12) << right << setprecision(2) << fixed << total << right << endl; cout << "Commission: " << setw(18) << "$ " << setw(12) << right << setprecision(2) << fixed << commission << right << endl; cout << "Total amount: " << setw(16) << "$ " << setw(12) << right << setprecision(2) << fixed << right << total + commission << right << endl; cout << "Net worth in " << setprecision(0) << fixed << time << " years: "; /*These nested if-statements are uses because when time changes from 1 digits number to 2 digit number the width changes so I had to implement these if-statements so that when the digits changes the setw(); changes as well. */ if (time < 10) { cout << setw(8) << "$ " << setprecision(2) << setw(12) << right << fixed << right << finalmoney << endl; } else if (time > 9 && time < 100) { cout << setw(7) << "$ " << setprecision(2) << setw(12) << right << fixed << right << finalmoney << endl; } else { cout << setw(6) << "$ " << setprecision(2) << setw(12) << right << fixed << right << finalmoney << endl; } } else if (answer == "no") { cout << "Have a Nice Day!"; //If the user inputs an answer that is not yes or no. } else { cout << "Sorry, " << user_name << ", " << endl << "this is an invalid selection" << endl; cout << "Please Run the program again."; } cout<<" "<<endl; } //The retirement Plan Part B. void Retirement_planning() { infile.open("input.txt"); infile >> base; infile >> anual_growth; infile >> monthly_contribution; infile >> num_years; begining_value = base; for (int i = 1; i <= num_years; i++) { base += ((12 * monthly_contribution) * (anual_growth / 100.0)) + (12 * monthly_contribution); } outfile.open("output.txt"); outfile << "Name: " << setw(20 + (user_name.length())) << user_name << endl; outfile << "Base: " << setw(24) << begining_value << endl; outfile << "Anual growth rate: " << setw(8) << anual_growth << endl; outfile << "Monthly contribution: " << setw(8) << monthly_contribution << endl; outfile << "Years: " << setw(21) << num_years << endl; outfile << "Networth after " << num_years << " years: " << setw(7) << base << endl; cout << "Everything has been written to the output file. :D" << endl; infile.close(); outfile.close(); cout<<" "<<endl; } //Mortage Function that asks and outputs the Mortgage Plan. void Mortgage() { cout<<user_name<<" please enter the following: "<<endl; cout<<"Principle: "<<endl; cin>>mortgage_principle; cout<<"Interest rate: "<<endl; cin>>mortgage_rate; cout<<"Lone Term(Number of monthly payments): "<<endl; cin>>mortgage_term; //equation mortgate_monthly_rate= ((((mortgage_rate/100.0)/12.0)*(mortgage_principle))) /(1-(pow(1+((mortgage_rate/100.0)/12.0),(mortgage_term*(-12))))); cout<<"Hello, "<<user_name<<endl; cout<<"Principle: "<<mortgage_principle<<endl; cout<<"Interest rate: "<<mortgage_rate<<endl; cout<<"Lone Term(Number of monthly payments): "<<mortgage_term<<endl; cout<<"Monthly Mortgage Rate: "<<setprecision(2)<<fixed<<mortgate_monthly_rate<<endl; cout<<" "<<endl; }