Nov 20, 2014 at 6:39pm UTC
MY program is running incorrectly, it will not calculate the correct salary with a 10% raise, can someone help please.
// File: Lab 22P2.cpp
// Created by Man-Chi Leung on 3/22/14
// This program reads a number from keyboard.
// It uses two functions to calculates new salary after 5% raise and 10% raise.
#include <cstdlib>
#include <iostream>
using namespace std;
void fivePercentRaise(double &);
void tenPercentRaise(double &);
int main()
{
double salary = 0.0;
cout << "Please enter current salary: ";
cin >> salary;
fivePercentRaise(salary);
tenPercentRaise(salary);
system("pause");
return 0;
}
void fivePercentRaise(double & sal)
{
sal = sal + sal * 0.05;
cout << "New salary if you receive a 5% raise: " << sal << endl;
}
void tenPercentRaise(double & sal)
{
sal = sal + sal * 0.10;
cout << "New salary if you receive a 10% raise: " << sal << endl;
}
Nov 20, 2014 at 6:45pm UTC
Are you trying to calculate the 10% off of the base salary or after the 5% raise?
Nov 20, 2014 at 6:47pm UTC
You pass by refrence so it gets a 5% increase then a 10% increase also these 2 functions could easily be 1 if you had a second parameter
Last edited on Nov 20, 2014 at 6:47pm UTC
Nov 20, 2014 at 6:48pm UTC
i am trying to calculate the 10% off the base salary. I figured it was getting a 5% and a 10%, would doing a return statement fix that?
Nov 20, 2014 at 6:58pm UTC
To calculate the 10% of the base salary you need to -- Salary/10 (divided by 10)
so, 10% of base salary = salary/10.0 ;
ps. Giblit is right, remove the "& " from your function parameters,you dont need that for your assignment.
Last edited on Nov 20, 2014 at 6:59pm UTC
Nov 20, 2014 at 6:59pm UTC
Just pass by copy instead of reference so remove &