Ok, I am trying to work through this program and it is stopping at asking me what is my current salary. The problem is this:

Starting January 1st, of each year for three years, I will be getting a raise of .05 on my previous years salary. I wasnt a program that calculates and displays the amount of salary of $10,000 ( The raise amounts are $500.00, $525.00, $ 551.25. The total salary is $33,101.25)

Below is what I have got. I have to do this problem with a while statement.

#include <iostream>
#include <iomanip>

using namespace std;
int main()
{
	//declare variables

	int year3 = 0;
	int year2 = 0;
	int year1 = 0;
	double current_salary = 0.0;
	double raise = 0.0;
	double totalSalary = 0.0;
	const double rate = 1.05;

	//Enter Salary
cout << "Enter Annual Salary: $ " ;
cin >> current_salary;

while ((year1 < 4 && year1 > 0) (year2 = 1 && year2 < 4) (year3 > 0 && year3 < 4));
{
	year1 = current_salary * raise;
	year2 = year1 * raise;
	year3 = year2 * raise;
	current_salary =  year1 + year2 + year3;
	totalSalary += current_salary;
	
} //end while

cout << "Raise for year 1:$ " << year1 << endl;
cout << "Raise for year 2:$ " << year2 << endl;
cout << "Raise for year 3:$ " << year3 << endl;
cout << fixed << setprecision(2);
cout << "Total salary for the three years:$ " << totalSalary << endl;

system("pause");
return 0;
} //end of main function

Would someone please help me with this?

Thank you in advance.

On line 21, why are you assigning year2 the value of 1?

Maybe I should of done this action:

Still not working

#include <iostream>
#include <iomanip>

using namespace std;
int main()
{
	//declare variables

	int year = 0;
	double salary = 0.0;
	double raise = 0.0;
	double totalSalary = 0.0;
	const double rate = 1.05;

	//Enter Salary
cout << "Enter Annual Salary: $ " ;
cin >> salary;

while (int year = 1; year < 4; year += 1)
{
	raise = salary * rate;
	salary += raise;
	totalSalary += salary;
}//end while

cout << "Year: " year << "Raise:$ " << raise << endl;
cout << fixed << setprecision(2);
cout << "Total salary for the three years:$ " << totalSalary << endl;

system("pause");
return 0;
} //end of main function

@ line 19: you mistook a while loop for a for loop
@ line 26: you forgot to put << before year

Ok, I have changed my coding to the following:

#include <iostream>
#include <iomanip>

using namespace std;
int main()
{
//declare variables

double year1 = 0.0;
double year2 = 0.0;
double year3 = 0.0;
double salary = 0.0;
double raise = 0.0;
double totalSalary = 0.0;
const double rate = .05;

//Enter Salary
cout << "Enter Annual Salary: $ " ;
cin >> salary;

// Calculation

year1 = salary *(1.+ rate);
year2 = year1 * (1.+rate);
year3 = year2 * (1.+rate);
totalSalary = year1 + year2 + year3;

cout << fixed << setprecision(2);

cout << "After Year 1: $ " << year1 << endl;
cout << "After Year 2: $ " << year2 << endl;
cout << "After Year 3: $ " << year3 << endl;
cout << "Total salary for the three years:$ " << totalSalary << endl;

//system("pause");
return 0;
} //end of main function

It is giving me the correct output but after putting in the "Annual Salary: "; it is flashing the output box once and then it will go away. It wont stay up and on the screen for a split second then it will go away. Not sure why it is doing that.

Next time do please wrap your code between

tags so it will be easier to read the code

It is giving me the correct output but after putting in the "Annual Salary: "; it is flashing the output box once and then it will go away. It wont stay up and on the screen for a split second then it will go away. Not sure why it is doing that.

what compiler are you using?

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.