3
I am "programming in C", but compiling using the extension .cpp
and the g++ to have some facilities. My goal is to make a program that receives a starting salary and calculates the final salary according to certain bonus. The bonus is given in percentage over the initial salary, and if the function is called without being passed a value for the bonus, it must assume the value of 15%.
What I did:
#include <cstdio>
float calculaSalario(float* salario, float* bonificacao = 15.0f);
int main (void)
{
float salario = 0;
float bonificacao = 0;
scanf("%f", &salario);
scanf("%f", &bonificacao);
calculaSalario(&salario, &bonificacao);
printf("%f\n", salario);
return 0;
}
float calculaSalario(float* salario, float* bonificacao = 15.0f)
{
*salario = *salario + *salario * (*bonificacao/100);
}
However, I am getting the following errors:
error: could not float calculaSalario(float* salario, float* bonus = 15.0f);
In function ‘float calculaSalario(float*, float*)’: error: default argument given for parameter 2 of ‘float calculaSalario(float*, float*)’ [-fpermissive] note: previous specification in ‘float calculaSalario(float*, float*)’ here float calculaSalario(float* salario, float* bonus = 15.0f);
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero