0

Who do this program always output 50 everytime i input 50 and then 100??

#include <stdio.h> int main(){ int una, ikalawa; int marka; int average, score; printf("Enter your score: "); scanf("%d", &una); printf("Enter the number of items: "); scanf("%d", &ikalawa); average = (una/ikalawa) * 50 + 50; printf("%d", average); return 0; }

27th Jul 2018, 12:43 PM
Kari Gakure
Kari Gakure - avatar
2 Antworten
0
because (una/ikalawa) is result as 0... because 50/100 becomes 0.5 is converted to 0 being both variable are as of int type.... your code should be updated with below: double perc = (double)una/ ikalawa ; average = perc * 50 + 50;
27th Jul 2018, 1:08 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
thank you so much!
27th Jul 2018, 2:31 PM
Kari Gakure
Kari Gakure - avatar