Beginner Needing Help making change
This is my code so far:
Code:
#include <iostream>
using namespace std;
int main(){
int cent;
int quarter = 25;
int dime = 10;
int nickel = 5;
int penny = 1;
cout << "Enter an amount in cents: ";
cin >> cent;
cout << "The amount you entered is: " << cent << " cents\n";
cout << endl;
//This is where I am getting lost
if (cent % quarter)
cout << "Quarters: " << cent << endl;
if (cent % dime)
cout << "Dimes: " << cent << endl;
if (cent % nickel)
cout << "Nickels: " << cent << endl;
if (cent % penny)
cout << "Pennies: " << cent << endl;
system("pause");
return 0;
}
I have been having a lot of trouble with this one. I am trying to prompt the user for an amount of change, then determine how many quarters, nickels, dimes, and pennies the entered amount would make. I may have been staring at this for too long the longer I look at this the worse my code becomes. Any help would be greatly appreciated..
doh I was wayyyy over thinking this thing
Code:
#include <iostream>
using namespace std;
int main(){
int cent;
int quarter = 25;
int dime = 10;
int nickel = 5;
int penny = 1;
int solveQ;
int solveD;
int solveN;
int solveP;
int remainQ;
int remainD;
int remainN;
cout << "Enter an amount in cents: ";
cin >> cent;
cout << endl;
cout << "The amount you entered is: " << cent << " cents\n";
cout << endl;
solveQ = cent / quarter; //Finds # of Quarters
remainQ = cent % quarter; //Finds remaining cents
solveD = remainQ / dime; //Finds # of Dimes
remainD = remainQ % dime; //Finds remaining cents
solveN = remainD / nickel; //Finds # of Nickels
remainN = remainD % nickel; //Finds remaining cents
solveP = remainD / penny; //Finds # of Pennies
cout << solveQ << " Quarter(s)" << endl;
cout << solveD << " Dime(s)" << endl;
cout << solveN << " Nickel(s)" << endl;
cout << solveP << " Penny(s)\n" << endl;
system("pause");
return 0;
}
It's not 100% right but I believe I am on the right track now