- 1

Can someone debug this?

C programming It should output the denomination of the money. It worked for whole numbers, but for numbers with decimal places, it doesn't. #include<stdio.h> void main() { int rs = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0; float i = 0, j = 0, k = 0, l = 0; printf("Enter Amount : "); scanf("%d", &rs); while(rs >= 1000) { a = a + 1; rs = rs - 1000; } while(rs >= 500) { b++; rs = rs - 500; } while(rs >= 200) { c++; rs = rs - 200; } while(rs >= 100) { d++; rs = rs - 100; } while(rs >= 50) { e++; rs = rs - 50; } while(rs >= 10) { f++; rs = rs - 10; } while(rs >= 5) { g++; rs = rs Example input 2000 Output 1000: 2 500: 0 200: 0 100: 0 50: 0 20: 0 10: 0 5: 0 25 cents: 0 10 cents: 0 5 cents: 0 But if I inputed 2000.25 It doesn't read it

14th Sep 2019, 9:26 AM
Michael Gilbert Acuña
Michael Gilbert Acuña - avatar
3 ответов
0
#include<stdio.h> void main() { int rs = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0; float i = 0, j = 0, k = 0, l = 0; printf("Enter Amount : "); scanf("%d", &rs); while(rs >= 1000) { a = a + 1; rs = rs - 1000; } while(rs >= 500) { b++; rs = rs - 500; } while(rs >= 200) { c++; rs = rs - 200; } while(rs >= 100) { d++; rs = rs - 100; } while(rs >= 50) { e++; rs = rs - 50; } while(rs >= 10) { f++; rs = rs - 10; } while(rs >= 5) { g++; rs = rs - 5; } while(rs >= 1) { h++; rs = rs - 1; } while(rs >= 0.25) { i++; rs = rs - 0.25); } while(rs >= 0.10) { j++; rs = rs - 0.10; }
14th Sep 2019, 9:27 AM
Michael Gilbert Acuña
Michael Gilbert Acuña - avatar
0
while(rs >= 0.05) { k++; rs = rs - 0.05; } while(rs >= 0.01) { l++; rs = rs - 0.01; } printf("\n 1000 : %d", a) ; printf("\n 500 : %d", b) ; printf("\n 200: %d", c) ; printf("\n 100 : %d", d) ; printf("\n 50 : %d", e) ; printf("\n 10 : %d", f) ; printf("\n 5 : %d", g) ; printf("\n 1 : %d", h) ; printf("\n 25 cents : %f", i); printf("\n 10 cents : %f", j); printf("\n 5 cents : %f", k); printf("\n 1 cents : %f", l); return 0 ; }
14th Sep 2019, 9:27 AM
Michael Gilbert Acuña
Michael Gilbert Acuña - avatar
0
Here's the full code above
14th Sep 2019, 9:28 AM
Michael Gilbert Acuña
Michael Gilbert Acuña - avatar