Hi everyone, I have been a long time forum viewer but first time poster. I am really struggling with this project I am working on. I created the three functions but they are not being called when the input matched the else ifs. I really don't understand this problem. I have read so much about functions that I think I know less. Please any help would be appreciated. My errors are probably apparent to most of you right away.
I need these functions to be called upon when the user inputs the corresponding number.
Thank you all!
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void option1() // would this execute if 1 was entered? (see below "cin >> option")
{
years = retire - age;
cout << "You have " << years << " years until retirement." <<endl;
}
//----------------------------------------------------------------------------------
void option2()
{
cout << "How much do you make per week in dollars? ";
cin >> salary;
earnings = 52 * (salary * (retire - age));
cout << "You will earn $" << earnings << " between now and retirement. " << endl;
}
//-----------------------------------------------------------------------------------
void option3()
{
cout << "How much do you make per week in dollars? ";
cin >> salary;
cout << "What percentage will you save? ";
cin >> rate;
earnings = 52 * salary;
total = (rate / 100) * earnings;
years = retire - age;
cout << "There are " << years << " years till retirement." << endl;
savings = savingsNow;
pmt = (savings + total) / 52; // weekly payment made to retirement account
cout << "PMT is " << pmt << endl;
wr = .06 / 52; // wr is weekly intrest rate
cout << "wr is " << wr << endl;
n = 52 * years; //week until retirement
cout << "n is " << n << endl;
totalRetirement = (pmt) * (pow(1 + wr, n)-1) / (wr);
cout << "You will have $" << totalRetirement << " saved when you retire. " << endl;
}
//-------------------------------------------------------------------------------------------------------------
int main ()
{
string name;
double total, rate, salary, savings, intrest, savingsNow = 0, x, pmt, wr, n, totalRetirement;
int age, retire, option, years, earnings;
cout << "What is your name? ";
getline (cin, name);
cout << "How old are you? ";
cin >> age;
if ((age >= 60) && (age < 65))
retire = 65;
if ((age >= 50) && (age < 60))
retire = 67;
if ((age >= 40) && (age < 50))
retire = 70;
if (age < 40)
retire = 72;
do {
cout << "Please select an option: " << endl;
cout << "\t(1) Number of years to retirement " << endl;
cout << "\t(2) Amount earned between now and retirement " << endl;
cout << "\t(3) Amount saved at retirement " << endl;
cout << "\t(4) Exit (do nothing) " << endl;
cin >> option;
if (option == 1)
{
option1();
// Shouldn't this call the declared function above and send it back down here?!?!?
}
else if (option == 2)
{
option2();
}
else if (option == 3)
{
option3();
}
else
{
cout << "Please choose a valid option." << endl;
}
}while (option !=4);
cout << "Thanks for using our program!" << endl;
cout << endl;
}
Again, thank for looking guys. ANY help would be appreciated.