Calculating incorrectly- HELP please

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;
}
Are you trying to calculate the 10% off of the base salary or after the 5% raise?
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
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?
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
Just pass by copy instead of reference so remove &
got it, thanks!
Topic archived. No new replies allowed.