We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,939 Members — Technology Publication meets Social Media

# Pay Raise Calculator

``````#include <iostream>  // required to perform C++ stream I/O
#include <iomanip>  // required for parameterized stream manipulators

using namespace std;  // for accessing C++ Standard Library members

// function main begins program execution
int main(){
double wage = 0, raise = 0, raiseMoney = 0;
int years = 0;

// Prompt user to enter weekly wage
cout << "Enter starting weekly wage: ";
cin >> wage;
// Prompt user to enter amount of raise
cout << "Enter amount of raise (in %): ";
cin >> raise;
// Prompt user to enter years of employment
cout << "Enter years of employment: ";
cin >> years;

wage = wage * 52;
raiseMoney = (raise / 100) * wage;

cout << setprecision(2) << fixed;

cout << "\nYear   Annual Salary\n";
for(int i = 0 ; i < (years) ; i++)
{
cout << (i+1) << "      \$" << wage + (raiseMoney * i) << "\n";

}

cout << endl;

return 0;``````

The numbers are not adding up correctly: Can someon just check out the code and tell me what I am missing or did wrong, This is what it is supposed to print.

Year Annual Salary
1 26000.00
2 26780.00
3 27583.40
4 28410.90
5 29263.23
6 30141.13
7 31045.36
8 31976.72

Press any key to continue....

Any Help would be appreciated!!!

4
Contributors
8
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
9
Views
Question
maria536
Light Poster
26 posts since Sep 2011
Reputation Points: 6
Skill Endorsements: 0

Without your problem statement or the input you used it's hard to know just what your results should be. Offhand, I'd hazard a guess that you should be adding the raise to the annual wage before calculating the next year's raise.

Something like `wage = wage + (raiseMoney * i);`

vmanes
Postaholic
2,015 posts since Aug 2007
Reputation Points: 1,283
Skill Endorsements: 6

The equation should be
wage = wage * (1+(raiseMoney/100));

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Skill Endorsements: 17

Problem is not in your code but your logic. The expected output seems to be using compound interest but you implemented simple interest. Try..

``````float raisep = (raise/100);
for(int i = 0 ; i < (years) ; i++)
{
cout << (i+1) << " \$" << wage << "\n";
raiseMoney = raisep * wage;
wage = wage + raiseMoney;
}``````
vidit_X
Junior Poster
168 posts since Aug 2008
Reputation Points: 40
Skill Endorsements: 0

Oops, I forgot to fully engage brain before activating typing fingers. vidit X has a good solution there.

vmanes
Postaholic
2,015 posts since Aug 2007
Reputation Points: 1,283
Skill Endorsements: 6

Ok, I tried to fix it using the code that vidit x stated but there were too many errors. do I put the code after cin >> years?

maria536
Light Poster
26 posts since Sep 2011
Reputation Points: 6
Skill Endorsements: 0

Ok, I tried to fix it using the code that vidit x stated but there were too many errors. do I put the code after cin >> years?

How can you use it before taking the number of years from user? It cannot predict.

vidit_X
Junior Poster
168 posts since Aug 2008
Reputation Points: 40
Skill Endorsements: 0

I took out the line between 21 and 28 and entered what you said I should fix and I recieved some errors so I went back to my code. This is what I meant.

maria536
Light Poster
26 posts since Sep 2011
Reputation Points: 6
Skill Endorsements: 0

Thanks for you help vidit x, it works!!!

maria536
Light Poster
26 posts since Sep 2011
Reputation Points: 6