Write a program that has a function that takes a salary as argument. If the salary is less than 20000, give a 20% raise. Return the salary. I was not given any example. I need to know how to start it because I know the formula to raise the salary by 20% is <tot = tot + 0.2 * tot> (or whatever variable I choose to use).
#include <iostream>
usingnamespace std;
int get_salary(constint salary)
{
int new_salary = // your calculation here
return new_salary;
}
int main()
{
int orig_salary = 15000;
int new_salary = get_salary(orig_salary);
// show the result
}
Yes, there is. You need to check the value that the user entered, to see if it's greater than 20000. If it is, don't try and calculate the raise, and instead output the message.
<#include<iostream>
usingnamespace std;
int fun(sal)
{
if(sal >= 20000)
{
return(sal);
}
else
{
//if(sal<=20000) - no need for this test
return(sal + (0.2 * sal));
}
int main()
{
int sal;
cout << "Please enter the salary: \n";
cin >> sal;
sal = fun(sal);
cout << "The Final Salary is: " << sal << endl;
//or just
// cout << "The Final Salary is: " << (fun(sal)) << endl;
system("pause");
return 0;
}
You were calculating the final salary after you printed it.
Your using ints, ints don't have decimal places, you should consider using doubles.