Raise Program help

I would truly appreciate some help on this.


//displays the value of Khaild raise
//at the end of each of three years, using
//increase rates of 3%, 4%, 5% and 6%
//Created/revised by <name> on <date>

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

int main()
{
double currentSalary = 0.0;
double raise = 0.0;
double newSalary = 0.0;

cout << " Enter current Salary: ";
cin >> currentSalary;
cout << endl << fixed << setprecision(0);

for (double rate = 0.03; rate < 0.06; rate += 0.03)
{
cout << "Enter raise percent: " << rate * 100 << "%" << endl;
cin >> raise;

newSalary = currentSalary * rate;

for (int year = 1; year < 6; year += 1)
{
raise = currentSalary * rate;
newSalary += raise;
cout << year << " $" << newSalary << endl;
} //end for
cout << endl;
} //end for

return 0;
} //end of main function
I have made 6 to reflect a 4

for (int year = 1; year < 4; year += 1)
{
raise = currentSalary * rate;
newSalary += raise;
cout << year << " $" << newSalary << endl;
} //end for
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) What kind of help? You've told us nothing about what you want to achieve, nor about what problems you have with the code that you're trying to fix.

Help us to help you.
The program should calculate and display the amount of Khalid 's annual raise for the next three years using rates of 3%, 4%, 5% and 6%. The program should end when kahlid enters a sentinel value as the salary.


Use 30000 and 50000 for salaries during desk checks.
is it cumulative?
should it be
currentsalary *= rate+1.0?

also the loop over rate seems odd (why increment by 3%?)

I have modified it to this:


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

int main()
{
double currentSalary = 0.0;
double raise = 0.0;
double newSalary = 0.0;

cout << " Enter current Salary: ";
cin >> currentSalary;
cout << endl << fixed<< setprecision(0);

for (double rate = 0.03; rate < 0.07; rate += 0.01)
{
cout << "Enter raise percent: " << rate * 100 << "%" << endl;
cin >> raise;

for (int year = 1; year < 4; year += 1)
{
raise = currentSalary * rate;
newSalary += raise;
cout << year << " $" << newSalary << endl;
} //end for
cout << endl;
} //end for

return 0;
} //end of main function
I fixed it myself thanks.

Final program
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
//declare variables
double currentSalary = 0.0;
double raise = 0.0;
double newSalary = 0.0;

//enter input items
cout << " Enter current Salary: ";
cin >> currentSalary;
cout << endl << fixed<< setprecision(0);

//calculate
for (double rate = 0.03; rate < 0.07; rate += 0.01)
{
cout << "Enter raise percent: " << rate * 100 << "%" << endl;
cin >> raise;

newSalary = currentSalary;
for (int year = 1; year < 4; year += 1)
{
raise = currentSalary * rate;
newSalary += raise;
cout << year << " $" << newSalary << endl;
} //end for
cout << endl;
} //end for

return 0;
} //end of main function
Topic archived. No new replies allowed.