0

I am a c++ beginner, I want to write a USD/EUR exchange program, for the output I would like to write "You get how much $/€ and cents, but I don't know how, since I have to output only the number of cents.

double eur{0},usd{0},sum{0},kurs{1.14},x,c,d,y;

cout<<"Do you want change Euro or Dollar?"<<endl<<"a is for Euro in Dollar, b is for Dollar in Euro, put a oder b in: "<<endl;

char input = ' ';
cin>>input;
cout<<"Give the sum you want to exchange: ";
cin>>sum;
if (input == 'a'){
    usd=sum;
    x=usd*kurs;
    y= x*100%100; (MODULO is not usable, error, why?)

    cout<<"You get "<< x <<" dollar and " << y << "cents."
mch
  • 9,424
  • 2
  • 28
  • 42
Rodomo
  • 5
  • 2
  • 1
    Unrelated: don't use `double` for currencies, instead use an integer type representing some fixed fractional value. – Caleth Mar 25 '19 at 11:52

1 Answers1

1

You can use the floor function to get the integral part and subtract it from your number.

double dollars = floor(input);
double cents = (input - dollars) * 100;