int ---> 0.1

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

1
2
3
  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:
1
2
3
int object,a;
a = 1-0.9;
object = 0+a;
Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>

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:
1
2
3
    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 :
1
2
3
4
    int myArray[6];
    int money,shopingCart;
    float shirt,pants,other;
    char item[6];

AND IT WORKED :D

And I Can do this to:
1
2
3
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.