I know that many beginners have issues with this problem, and I was able to solve it by using
float
s instead of using the below solution, but I don’t understand why the following solution (submitted solution here) received “Wrong Answer”:
#include <stdio.h>
#include <stdlib.h>
typedef short withdrawl;
typedef short parts;
typedef short deposit;
int main() {
withdrawl num;
parts beg, end;
deposit total;
scanf("%hi %hi.%hi", &num, &beg, &end);
total = 100*beg+end;
if (!(num % 5)) {
total -= num*100+50;
if (total < 0) total = 100*beg+end;
}
printf("%hi.%hhi%hhi\n", total/100, (total % 100)/10, total % 10);
exit(0);
}
I would really appreciate if someone could explain why the above solution didn’t pass. Thank you!