### Can you use Const Int with decimals?

I am writing a program that allows the user to input a dollar amount and in return gives them the amount of pennies, nickels, dimes, and quarters in that dollar amount. I am using the following code to set the constant value of each nickels, dimes, and quarters.

 ``123`` `````` const int Nickel = 5; const int Dime = 10; const int Quarter = 25;``````

Below that I am doing

 ``123`` `````` cout << "There are " << ((dollars * 100) / Nickel) << " nickels in " << dollars << " dollar(s)." << endl; cout << "There are " << ((dollars * 100) / Dime) << " dimes in " << dollars << " dollar(s)." << endl; cout << "There are " << ((dollars * 100) / Quarter) << " quarters in " << dollars << " dollar(s).\n\n" << endl;``````

I would prefer to replace the value of nickels, dimes, and quarters with a decimal value so that I didn't have to multiply by 100 and then divide. However, when I try that the program crashes when it tries to calculate these values.

Is this possible to do or do I have to go another route?
You can't use `const int` with fractional numbers, but your can use float or double.

 ``12345678`` `````` const double Nickel = 0.05; const double Dime = 0.10; const double Quarter = 0.25; const double dollars = 10.0; cout << "There are " << (dollars / Nickel) << " nickels in " << dollars << " dollar(s)." << endl; cout << "There are " << (dollars / Dime) << " dimes in " << dollars << " dollar(s)." << endl; cout << "There are " << (dollars / Quarter) << " quarters in " << dollars << " dollar(s).\n\n" << endl;``````

I removed the "const double dollars = 10.0" because I want dollars to be defined by the user as shown in the code below:

 ``123`` `````` int dollars; cout << name << ", please enter a whole dollar amount (greater than 1) to \nconvert to the coin currency equivelant: "; cin >> dollars;``````

Leaving that out everything worked perfectly though. Thank you much.
Topic archived. No new replies allowed.