Skip to content

Instantly share code, notes, and snippets.

@chrisabrams
Created June 25, 2020 16:14
Show Gist options
  • Save chrisabrams/a773684ca7c621ff3970ca403bb8264f to your computer and use it in GitHub Desktop.
Save chrisabrams/a773684ca7c621ff3970ca403bb8264f to your computer and use it in GitHub Desktop.
# include <iostream>
using namespace std;
int main ()
{
// It is good practice to define variables at the top of the file when possible
const int dollar {100};
const int quarter {25};
const int dime {10};
const int nickel {5};
const int penny {1};
int amount_of_cents {};
int modulo_result {};
int result {};
// Get cents from user
cout << "Please enter the amount of cents: " << endl;
cin >> amount_of_cents;
result = amount_of_cents / dollar;
modulo_result = amount_of_cents % dollar;
// Get dollar from user
cout << " dollars: " << result << endl;
result = modulo_result / quarter;
modulo_result = modulo_result % quarter;
// Get quarters from user
cout << "quarters: " << result << endl;
result = modulo_result / dime;
modulo_result = modulo_result % dime;
// Get dimes from user
cout << " dimes: " << result << endl;
result = modulo_result / nickel;
modulo_result = modulo_result % nickel;
// Not sure what you are trying to do here
cout << " nickels: " << result << endl;
result = modulo_result / penny;
cout << " pennies: " << result << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment