### How do you split dollars and cents from a net pay?

int main ()
{
double C,M;

cout << "Cost? " ;
cin >> C;
cout << "paying? " ;
cin >> M;
cout << "Your change is " << M-C << endl;

system ("pause");
return 0;
}

thats how far i gotten but i been stuck here for awhile. if anyone could give me some tips that would be great.
Last edited on
 ``123456789`` ``````// do something like this: double x = 25.75; // to get dollars int dollars = x; // the decimal is trunicated // to get cents int cents = (x % 1) * 100; // I haven't actually tried this, but I think it works ``````
@iNinjar

I tried blueeyedlion's way, and received an error on using the mod. I tried it this way, and I get correct results. It may help you, also.
 ``123456789`` ``````float x = 25.75; // to get dollars int dollars = x; // the decimal is trunicated // to get cents int cents =(x - dollars)*100; // I tried, this works cout << "You have " << dollars << " dollars and " << cents << " cents." << endl;``````
thanks for the help guys
Topic archived. No new replies allowed.