# C++ help

Show 75 post(s) from this thread on one page
Page 3 of 3 First 123
• July 20th, 2007
WebDrake
Re: C++ help
Quote:

Originally Posted by sdmike
What is "static_cast<int>"?

It's a way of type casting, that is, converting data from one of C++'s number types to another. In this case you want to convert from a float to an int.

In C you would write,
Code:

`change = (int) (t*100)`
but I think in C++ the use of static_cast<> is safer.

http://www.codeproject.com/cpp/static_cast.asp
• April 17th, 2013
umairsario
Re: C++ help
Problem is at
pennies = (int)(amount / 0.01);

if you want in INT you will always have answer in 0; so you cant calculate pennies.

so you have to change it to..

pennies = (amount / 0.01);

now another thing to do is.. make it round ....

int roundingp = pennies+0.5;

and then
pennies = roundingp;

if i paste your program after making some change here it will be !
Code:

``` # include <iostream.h> #include<conio.h> float amount; float quarters; float dimes; float nickels; float pennies; int main() { cout << "Enter an amount less than \$1.00: "; cin >> amount; //if (amount == 0) quarters = (int)(amount / 0.25); amount -= (quarters * 0.25); dimes = (int)(amount / 0.10); amount -= (dimes * 0.10); nickels = (int)(amount / 0.05); amount -= (nickels * 0.05); pennies = (amount / 0.01); //cout<< pennies; cout << "You have " << quarters << " quarters" << ".\n"; cout << "You have " << dimes << " dimes" << ".\n"; cout << "You have " << nickels << " nickels" << ".\n"; int roundingp = pennies+0.5; pennies = roundingp; cout << "You have " << pennies << " pennies" << ".\n"; getch(); return 0; }```
Result Snapshopt
where input is 0.11

Enter an amount less then \$1.00: 0.11
You have 0 quaters.
You have 1 dimes.
You have 0 quaters.
You have 1 pennies.

Reply if having any difficulty !
• April 17th, 2013
howefield
Re: C++ help
• April 17th, 2013
Bucky Ball
Re: C++ help