#include <iostream>
#include <string> 
using namespace std;

int main()
{
		// Variable declarations allowing us to calculate 
		string fullName;
		int weeklySalary;
		int weeks; 
		string age; 
		int option; 
		int actualage; 
		int earnings; 
		double savingsPercentage;
		double percentage; 
		int retirementage; 
		double total;
		cout << "What is your name? "; 
		getline(cin, fullName); 
		cout << "How old are you? ";
		cin >> age;
		cin.ignore(); // Removes the control character...
		cout << "Please select an option: " << endl;  // Main menu allowing selection of option.
		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; 
		cin.ignore(); // Removes the control character...
		do
		{
			if	(option == 1)
			cout << option << " "; 
		}
			// The code in Case 1 calculates the Number of years you have.  
			cout << "You have " << actualage << " years until retirement." << endl; 
			cout << "Please select an option: " << endl;  // Main menu allowing selection of option...
			cin >> option; 
			cin.ignore(); // Removes the control character...
		do
		{	
		else if (option == 2)
		{
		cout << option << " "; 
		}
			// The code in case 2 calculates the Amount Earned between now and retirement by age.
			cout << "How much do you make per week in dollars? "; 
			cin >> weeklySalary;
			cin.ignore(); // Removes the control character...
			weeks = (52 * actualage); 
			earnings = (weeks * weeklySalary);   
			cout << "You will earn " "$"<< earnings << " between now and retirement." << endl; 
			cout << "Please select an option: " << endl;  // Main menu allowing selection of option...
			cin >> option; 
			cin.ignore(); // Removes the control character...
		do 
		{
		else if (option == 3)
		cout << option << " ";  
		} 
			// The code in case 3 calculates the Amount Saved at Retirement taking into account the savings rate...
			cout << "How much do you make per week in dollars? "; 
			cin >> weeklySalary;
			cin.ignore(); // Removes the control character...
			weeks = (52 * actualage); 
			earnings = (weeks * weeklySalary); 
			cout << "What percentage will you save? ";
			cin >> savingsPercentage;
			cin.ignore(); // Removes the control character...
			percentage = (savingsPercentage / 100); 
			total = (percentage * earnings);
			cout <<	"You will have " << total << " saved when you retire << endl;    
			cin >> option; 
			cin.ignore(); // Removes the control character...
		do
		{
			else if (option == 4)
			cout << option << " "; 
		}	
			cout << "Thanks for using our program." << endl; 		

}

"I am trying to use a Do While Loop per the requirements"

Recommended Answers

All 5 Replies

why dont u use a
switch(option)
case 1:
Numbers of year...
break;
case 2:

and keep going
much easier to debug

We could help if you put the code within a [ CODE]***
[/code] in the advanced editor so we can see it more clearly

When you make a post and it looks bad, click the EDIT button to the left and fix it!

commented: :) +12

You claim to be using a DO-WHILE loop. I see the DO. What's missing?

Each do loop needs a while condition, such as:

bool done = false;
do
{
   // Stuff to do
   if (no_more_stuff_to_do)
   {
       done = true;
   }
}
while (!done);

// Or

while (!done)
{
    // Stuff to do
    if (no_more_stuff_to_do)
    {
       done = true;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.