2
I’m learning to code in C using the book Linguagem C - Completa e mplicada by André Backes. There is an exercise that I cannot get the answer right. Follow the Statement:
(The exercise has been slightly modified) Make a program that reads a worker’s salary and loan amount requested. If the loan value:
- For 20 % higher than salary, print: "Loan not granted."
- Otherwise, print: "Loan granted."
follows below my code
int n1; // salário
int n2; // valor empréstimo
int resultado;
scanf ("%d %d",&n1,&n2);
resultado = n2/n1;
if (resultado <= 1.2){
printf("emprestimo concedido");
}else{
printf("emprestimo nao concedido");
}
return 0;
Wow, I forgot this detail: decimal part :/ and use float or double for variable result. Anyway the program does not run correctly. You can make it work just by using if or switch?
– Misael
I had to declare all variables as float and now it worked except when the amount is exactly 20% more than the salary ("should accept the loan but is not").
– Misael
It is there showing that it works. I see no reason to use
if
in this case, even less withswitch
. Like I said, usefloat
for monetary value does not work even.– Maniero
Yeah, I tried using
if
because the exercise is in the chapter of the book that teaches Conditional Control Command. Anyway, thanks for the help!– Misael