Created
February 8, 2016 03:31
-
-
Save brunoparga/7d9870c62990489bc788 to your computer and use it in GitHub Desktop.
A snippet from the program to make change
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
// Corrects grammar | |
string q_gram = (quarters == 1) ? "quarter" : "quarters"; | |
string d_gram = (dimes == 1) ? "dime" : "dimes"; | |
string n_gram = (nickels == 1) ? "nickel" : "nickels"; | |
string p_gram = (pennies == 1) ? "penny" : "pennies"; | |
// Outputs the change | |
printf("Your change is: "); | |
if (quarters != 0) | |
{ | |
printf("%d %s, ", quarters, q_gram); | |
} | |
if (dimes != 0) | |
{ | |
printf("%d %s, ", dimes, d_gram); | |
} | |
if (nickels != 0) | |
{ | |
printf("%d %s, ", nickels, n_gram); | |
} | |
if (pennies != 0) | |
{ | |
printf("and %d %s.", pennies, p_gram); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment