Last active
September 20, 2018 19:30
-
-
Save ppgallas/d906418986ecc6746ba130485e1c81f3 to your computer and use it in GitHub Desktop.
A program which counts the smallest amount of coins to give out change in the store.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <cs50.h> | |
#include <math.h> | |
int main(void) | |
{ | |
float cash; | |
int change; | |
int amountOfCoins; //counting coins | |
int coins[] = {25, 10, 5, 1}; | |
int i = 0; | |
do | |
{ | |
cash = get_float("How much money in $ do you have?\n"); //asks user for amount of money he has | |
} | |
while (cash <= 0); | |
change = roundf(cash * 100); | |
amountOfCoins = 0; | |
while (change > 0) | |
{ | |
if (change >= coins[i]) | |
{ | |
change -= coins[i]; | |
amountOfCoins++; | |
} | |
if (change < coins[i]) | |
{ | |
i++; | |
} | |
} | |
printf("Coins: %i\n", amountOfCoins); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment