Skip to content

Instantly share code, notes, and snippets.

@kylecannon
Last active December 22, 2015 02:59
Show Gist options
  • Save kylecannon/4e0d8092c8bdd207d7b6 to your computer and use it in GitHub Desktop.
Save kylecannon/4e0d8092c8bdd207d7b6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main()
{
double owe,pay,change, negative;
int quarter = 0,dime = 0 ,nickle = 0 ,pennie = 0;
printf("How much did the product you want cost?\n");
scanf("%lf",&owe);
printf("How much money will you be paying?\n");
scanf("%lf",&pay);
if (pay < owe || owe < 0)
{
printf("I'm sorry you don't have enough money to pay for this item\n");
negative = -1*(pay-owe);
printf("You owe %.2f more\n",negative);
printf("Goodbye\n");
return 0;
}
printf("If this is true you will be paying %.2f for a product costing %.2f\n", pay, owe);
change=pay-owe;
printf("You will recieve %.2f in change\n",change);
while (change >= 0.25)
{
quarter++;
change=change-0.25;
}
printf("%i:quarters\n",quarter);
while (change >= 0.1)
{
dime++;
change=change-0.1;
}
printf("%i:dimes\n",dime);
while (change >= 0.05)
{
nickle++;
change=change-0.05;
}
printf("%i:nickle\n",nickle);
printf("%.2f change\n", change);
while (change < 0.05)
{
pennie++;
change=change - 0.01;
}
printf("%i:pennie\n",pennie);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment