### int ---> 0.1

Hi, i would like to know how to make an "int" have a fraction...
Like this:

 ``123`` `````` int object; object = 0.1;``````

BUT OF COURSE I DOSE NOT WORK
Can Anyone help? Many Call it a Long Int but i tryed it & it did not work.

`cout << "Thanks";`
That is not it, my problem is:
I can not make it Zero point One.
Also i can not do:
 ``123`` ``````int object,a; a = 1-0.9; object = 0+a;``````
Here is the code:
 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include using namespace std; int main() { int myArray[6]; int money,shopingCart; long int shirt,pants,other; char item[6]; money = 25 ; shopingCart = 0 ; shirt = 8.95 ; pants = 9.95 ; other = 3.65 ; cout<< "Time to shop... Its BOXING Day!" << "\n" ; cout<< "\n" << "Please select the item you wish to buy." << "\n" ; cout<< "--------------------------------------------------------" << "\n" ; cout<< "------ Shirt ------------ Pants ----------- Other ------" << "\n" ; cout<< "------ \$" << shirt << " ------------ \$" << pants << " -----------\$ " << other << " ------" << "\n" ; cout<< "--------------------------------------------------------" << "\n" ; cout<< "~ You Have Currently: " << money << " \$ " << "\n" ; cin >> item; if (item == "shirt") { cout<< "You requested a shirt"; } system("pause"); } //NOT DONE ``````

The Prob is at:
 ``123`` `````` shirt = 8.95 ; pants = 9.95 ; other = 3.65 ;``````
You are trying to assign a floating point number to a variable that is an integer.

`long int shirt,pants,other;`

Try.

`float shirt, pants, other;`

In fact I would also look at the implementation of your other variables as well and see if they need to be floats or doubles.
Thank You SO Much.
That relay helped.
:D
So i put it :
 ``1234`` `````` int myArray[6]; int money,shopingCart; float shirt,pants,other; char item[6];``````

AND IT WORKED :D

And I Can do this to:
 ``123`` ``````float object,a; a = 1-0.9; object = 0+a;``````

But its kinda useless :3 `// Thanks Again! `
Last edited on
Topic archived. No new replies allowed.