Last active
August 29, 2015 14:26
-
-
Save JamesCalleja/87f10958247580d19c82 to your computer and use it in GitHub Desktop.
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 <float.h> | |
#include <math.h> | |
// declare global variables | |
float change; | |
//declare functions | |
float GetChange(float i); | |
float MakeChange(float j); | |
//main application logic | |
int main() | |
{ | |
change = 0; | |
change = GetChange(change); | |
change = roundf(change * 100); | |
//printf("change is:%f\n", change); | |
MakeChange(change); | |
} | |
//define functions | |
float GetChange(float i) | |
{ | |
do | |
{ | |
printf ("Enter the amount of change owed:\n" ); | |
scanf ("%f", &i); | |
if (i < 0 ) | |
{ | |
printf ("Please enter a positive number\n"); | |
} | |
}while(i < 0); | |
return i; | |
} | |
float MakeChange(float j) | |
{ | |
int qCount = 0; | |
int dCount = 0; | |
int nCount = 0; | |
int pCount = 0; | |
int coinCount = 0; | |
while(change >= 25) | |
{ | |
change = change - 25; | |
qCount++; | |
//printf("qCount is:%i\n", qCount); | |
//printf("change is:%f\n", change); | |
}; | |
while(change >= 10) | |
{ | |
change = change - 10; | |
dCount++; | |
//printf("dCount is:%i\n", dCount); | |
//printf("change is:%f\n", change); | |
}; | |
while(change >= 05) | |
{ | |
change = change - 05; | |
nCount++; | |
//printf("nCount is:%i\n", nCount); | |
//printf("change is:%f\n", change); | |
}; | |
while(change >= 01) | |
{ | |
change = change - 01; | |
pCount++; | |
//printf("pCount is:%i\n", pCount); | |
//printf("change is:%f\n", change); | |
}; | |
coinCount = qCount + dCount + nCount + pCount; | |
printf("To make correct change you need %i coins\n%i quarters, %i dimes %i nickels, and %i pennies", coinCount, qCount, dCount, nCount, pCount); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment