For example if someone enters $999.99
how do i split it into the 900 part , 99 , and the 99 cents?
so it will read out like a check.
(nine hundred ninety nine dollars and 99 cents)
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
using namespace std;
int main()
{
double input;
int int_part;
int dec_part;
input=123.45;
int_part=input;
dec_part=(input-int_part)*100;
cout << "int_part: ";
cout << int_part << endl;
cout << "dec_part: ";
cout << dec_part << endl;
//now that you have them separated
//and stored in ints, you can use
//the modulo operator (%) to get
//the digits you want
cout << (int_part-int_part%100) << endl;
cout << int_part%100 << endl;
cout << dec_part<< endl;
cin.get();
return 0;
}
|
Last edited on
Line 19:
cin >> (*input);