C program to calculate change -
i trying write program calculate change, doesn't seem work. think problem owed 1/ paid 1; when tried print there values got nothing (0). ?
#include <stdio.h> int main() { double owed, paid; int dollars, quarters, dimes, nickels, cents, remainder, owed1, paid1; printf("how did customer have pay ?\n"); scanf("%f",&owed); printf("how did customer pay ?\n"); scanf("%f",&paid); owed1 = owed * 100; paid1 = paid * 100; int change = paid1 - owed1; dollars = change / 100; remainder = change % 100; quarters = remainder / 25; remainder = remainder % 25; dimes = remainder / 10; remainder = remainder % 10; nickels = remainder / 5; remainder = remainder % 5; cents = remainder; printf("%d",dollars); printf("dollars:%d, quarters:%d, dimes:%d, nickels:%d, cents:%d", dollars , quarters , dimes , nickels , cents ); return 0; }
you're using %f
in scanf, format specifier float, variables doubles. should use %lf
instead:
scanf("%lf",&owed);
same thing paid
. should getting warning compiler that.
Comments
Post a Comment