Hey guys!
I'm trying to write a program that involves a switch/case on Microsoft Visual Studion 2010. Unfortunately, some of my variables are not being initialized. I am a very novie programmer so please have mercy on me! Two of my options (1,4) are working but options (2,3) are not. I"m getting a run-time error I think.
Here is my program so far...
Any help would be greatly appreciated!!
#include <iostream>
#include <string>
using namespace std;
int main ()
{
// Variable declarations
string name;
// Input
int salary, earnings, yearsWorking, retireAge, option;
double age, savings, savePercentage;
cout << "What is your name? ";
getline (cin, name);
cout << "How old are you? ";
cin >> age;
if (age >=60)
retireAge = 65;
if ((age < 60) && (age >= 50))
retireAge = 67;
if ((age < 50) && (age >= 40))
retireAge = 70;
if (age < 40)
retireAge = 72;
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;
switch (option)
{
case 1:
yearsWorking = (retireAge-age);
cout << "You have " << yearsWorking << " years until retirement.";
break;
case 2:
earnings = (yearsWorking * (52 * salary));
cout << "How much do you make per week in dollars? ";
cin >> salary;
cout << "You will earn $" << earnings << " between now and retirement.";
break;
case 3:
savings = (earnings * (savePercentage/100));
cout << "How much do you make per week in dollars? ";
cin >> salary;
cout << "What percentage will you save? ";
cin >> savePercentage;
cout << "You will have $" << savings << " when you retire.";
break;
case 4:
break;
}
}