I had a function (money) needs two parameters (salary, days)
every week there are 2 holidays so working days = days – (weeks * 2)
you only spend money on working days
i want to calculate how much money do you spend per day
so i did –> salary / working days = sometimes this must equal floating point number but i don’t get it
#include <iostream>
using namespace std;
int money(float salary, int days)
{
// every week you have 2 days off
// you only spend money on working days
float workingdays = days - ( (days / 7) * 2 );
return salary / workingdays;
}
int main()
{
cout << money(2015, 21) << "\n"; // 134.333
cout << money(4500, 40) << "\n"; // 150
return 0;
}
in the first call i need the function money to return 134.33333333 but it returns 134
why??
>Solution :
Because in the money function you are returning int so the function return int value .Modify int with float , then your money function return float value
`
float money(float salary, int days){
float workingdays = days - ( (days / 7) * 2 );
return salary / workingdays;
}