Express number to dollars and cents

Hi there :), I have a problem with one excercise and I just can't figure it out. I hope someone can help me with this exercise:

Create a program that amount of money, expressed in cents printed dollars and cents. For example, if given 5005, it should print: 50 dollars and 5 cents. If given a 100, you need to print 1 dollar.
Last edited on
int money=0;
cout << "please enter money"<<endl;
cin >> money;
int cents = money % 100;
int dollars = money / 100;
cout << dollars << " dollars and " << cents << " cents";

Oh my God, I even didn't realise I can write it like this. It's so simple. Now I feel very dumb ;S. Thank you very much, abhishekm71, :).
Last edited on
you're welcome!
Topic archived. No new replies allowed.