Hello, I am having trouble with this nested loops. Can someone explain how to solve this problem?
Task:
At the beginning of every year, Paul receives a raise on his previous year's salary. He wants a program that calculates and displays the amount of his annual raises for the next three years, using rates of 3%, 4%, 5%, and 6%. The program should end when Paul enters a sentinel value as the salary.
What it should look like:
Sample run:
Salary (negative number or 0 to end): 100
Raise rate: 3%
Year 1: Raise: $3.00
Year 2: Raise: $3.09
Year 3: Raise: $3.18
Raise rate: 4%
Year 1: Raise: $4.00
Year 2: Raise: $4.16
Year 3: Raise: $4.33
Raise rate: 5%
Year 1: Raise: $5.00
Year 2: Raise: $5.25
Year 3: Raise: $5.51
Raise rate: 6%
Year 1: Raise: $6.00
Year 2: Raise: $6.36
Year 3: Raise: $6.74
CPP Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double salary;
int maxyear = 3;
double raise;
int maxraise = 6;
cout << fixed << setprecision(2);
cout << "Hello this program will calculate your pay raise at the rate of" << endl;
cout << "3%, 4%, 5%, and 6% every year over 3 years." << endl;
cout << "Please enter your salary rate: ";
cin >> salary;
for (int raiserate = 3; raiserate <= maxraise; raiserate++)
{
for (int year = 1; year <= maxyear; year++)
{
cout << "Year " << year << ": \t" << raise << endl;
}
}
return 0;
}
So i understand the problem in how the outer loop only runs 1 cycle after the inner loop finishes its counter but how do i make it run concurrently as in the example above? Thank you very much in advance!
#include <iostream>
#include <iomanip>
usingnamespace std;
int main()
{
double salary;
double raise;
cout << fixed << setprecision(2);
cout << "Hello this program will calculate your pay raise at the rate of" << endl;
cout << "3%, 4%, 5%, and 6% every year over 3 years." << endl;
cout << "Please enter your salary rate: ";
cin >> salary;
cout << "Raise Rate: \t" << raiserate << "%" << endl;
raise = (salary *(raiserate*0.01));
salary += raise;
cout << "Year 1: \t" << raise << endl;
// do the following 2x
// calculate the newraiserate by the previous raiserate
// print out what you found.
//calculate the raise if the raise percent was 4 of the original salary.
// print out what you found
// do the following 2x
// calculate the newraiserate by the previous raiserate being 4%
// print out what you found.
// continue this process for each 5% and 6%
return 0;
}
I mixed in your code and some my pseudocode.
With this new code you will not need the int maxyear or the int maxraise. I hope this makes sense to you.