Chemistry of AI and Natural Life

Page 23

23 of 29

Greedy 07: It is actually this one that works! #include <cs50.h> #include <stdio.h> int main (void) { printf("amount owed: "); float amount= GetFloat(); float cents= 100.0*amount; float quarter= 0; float dime= 0; float nickel= 0; float penni= 0; while (cents>0) if (cents>=25.0) { cents=cents-25.0; quarter=quarter+1; } else if (cents>=10.0) { cents=cents-10.0; dime=dime+1; } else if (cents>=5.0) { cents=cents-5.0; nickel=nickel+1; } else if (cents>=1.0) { cents=cents-1.0; penni=penni+1; } printf("%f %f %f %f %f\n",quarter,dime,nickel,penni,quarter+dime +nickel+penni); } 


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.