this is sorta a vending machine program i had to do for my C++ class. originally we just needed to make it convert a cent amount to quarter dimes nickel and penny. i just fixed it up a bit to make it work better then what the teacher wanted. though i post it.
GeSHi (cpp):
/* by oulyt
* Cent convert Project
* 10/22/08
* Converts an entered amount
* of cents to quarter, dime,
* nickles and pennies
*/
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
int cent, penny, dime, nickle, quarter;
char z = 'y';
while(z=='y')
{
cout << "Enter a number of cents between 1 and 99 \n";
cin >> cent;
if ( cent > 0 && cent < 100 )
{
quarter = cent / 25;
cent %= 25;
dime = cent / 10;
cent %= 10;
nickle = cent / 5;
cent %= 5;
penny = cent / 1;
cent %= 1;
cout << "The amount of cents you entered is equal to \n";
cout << quarter << " quarter(s)\n";
cout << dime << " dime(s)\n" << nickle << " nickle(s)\n";
cout << penny << " penny(s) "<< endl;
}
else
{
cerr << "Please enter an amount between 1 and 99" << endl;
}
cout << "\nTry again? (y/n)";
cin >> z;
z = tolower(z);
}
}Created by GeSHI 1.0.7.18
this uses everything i learned so far except loops