Please, can someone help me in this exercise, because I really don't know too much about swaping!...I dont need to write the whole code, only a part of it when it's shown how I swap and round them...

_____

Write the code that swaps the value of two int variables. Then round both variables to the nearest tenth. example: (If x contains the value of 43 and y the value of 87, then after the swap, the x should contain the value 87, and y the value 43. After rounding, x should contain a value of 90, and y the value of 40. )

i got this, im not sure at all!...

firstValue As Integer
           secondValue As Integer

        firstValue = 43
        secondValue = 87
        

        firstValue = firstValue ^ secondValue
        secondValue = firstValue ^ secondValue
        firstValue = firstValue ^ secondValue

The thread sounds awfully familiar...

Alright, you've suffered enough. I'll try to help you out.
To swap you need to three int values.
Let a= 1st number
Let b = 2nd number
Let t = temp holder
To swap you need to set t equal to the first number (a)
then set the first number equal to the second (b)
Finally set the second number equal to the temp value.
This way a becomes b AND b becomes a.

Ok, thanks
I'll just try to write it down and try to code it and I'll post it hereto see if it's correct!

int a=17;
            int b=24;
            int t;
t == a;
a == b;
b == t;

It's just like that?

int a=17;
            int b=24;
            int t;
t == a;
a == b;
b == t;

It's just like that?

Well that's the right idea, but you only need to use one = sign.
You are assigning (=) not comparing (==).
Good work!

You do realize that == compares two values whereas = assigns a value. Therefore, it's...

t = a;
a = b;
b = t;

Ohh i see, yeah, I got confused with the equal sign and the assignment operator. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.