Skip to content

Instantly share code, notes, and snippets.

@brunoparga
Created February 8, 2016 03:31
Show Gist options
  • Save brunoparga/7d9870c62990489bc788 to your computer and use it in GitHub Desktop.
Save brunoparga/7d9870c62990489bc788 to your computer and use it in GitHub Desktop.
A snippet from the program to make change
// 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