Just making an intentionally repetitive if statement program for spare change, but for an unknown reason it shoots numbers that are supposed to be 0 to some max values? I would really like some help here as to why
#include <stdio.h>int main(void) { int a; int b; int c; int d; int e; int cha; scanf("%d", &cha); if(cha == 0){ printf("No change\n"); return 0; } if(cha >= 100){ a = cha / 100; cha = cha % 100; } if(100> cha && cha >= 25){ b = cha / 25; cha = cha % 25; } if(25 > cha && cha >= 10){ c = cha / 10; cha = cha % 10; } if(10 > cha && cha >= 5){ d = cha / 5; cha = cha % 5; } if(5 > cha && cha >= 1){ e = cha; } if(a == 1){ printf("%d Dollar\n",a); } if(a > 1){ printf("%d Dollars\n",a); } if(b == 1){ printf("%d Quarter\n",b); } if(b > 1){ printf("%d Quarters\n",b); } if(c == 1){ printf("%d Dime\n",c); } if(c > 1){ printf("%d Dimes\n",c); } if(d == 1){ printf("%d Nickle\n",d); } if(d > 1){ printf("%d Nickles\n",d); } if(e == 1){ printf("%d Penny\n",e); } if(e > 1){ printf("%d Pennies\n",e); } return 0;}
Below is an example as to what gets produced
Input
45
Your output
1 Quarter2 Dimes****875483616** Nickles****32766 Pennies**
Expected output
1 Quarter2 Dimes