#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!!!

Recommended Answers

All 8 Replies

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);

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

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;
}

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

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?

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.

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.

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

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.