multiply problem

ok so i got this code and x=1.5 and y= -2.5
instead of giving me a=0 and b= -3, it gives me a=0 b=0...
can you guyz please explain me why ? and the answer please?
here is the code (using codeblocks..)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
    int a,b,w;
    double x,y;
    cin>>x>>y;
    a=x*y;
    b=x/y;
    if(a<b){
        w=a;
        a=b;
        b=a;
    }
    if(x != int(x)){
        cout<<a<<' '<<b;
    }
    else cout<<b<<' '<<a;
}


Thanks to all!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
    int a,b,w;
    double x,y;
    cin>>x>>y; // x = 1.5, y = -2.5
    a=x*y; // 1.5 * (-2.5) = -3.75 = -3 because a is an int
    b=x/y; // 1.5 / -2.5 = -0.6 = 0 because b is an int
    if(a<b){ // true because -3 < 0
        w=a; // w = -3
        a=b; // a = 0
        b=a; // b = 0
    }
    if(x != int(x)){ // true because 1.5 != 1
        cout<<a<<' '<<b; // prints "0 0"
    }
    else cout<<b<<' '<<a;
}
Thank you for your answer ,fg109.
Soo...man, how can i edit the program to print 0 -3 ? :-s
ohh sorry, i got it !
instead of using b=a i will use b=w.
thank you alot !
1
2
3
4
5
    if(a<b){
        w=a;
        a=b;   // <------------------- you know what this
        b=a;   // <------------------- and this means...?
    }
Topic archived. No new replies allowed.