hey all...Im trying to make a converter (miles to km)-nothing new really. and there's the method of taking three variables and then printing the result eg say a multiplication. And then there's this;
Because you are calculating the kilometers BEFORE you enter the miles. This is bad. It cannot work. You must get the number first, and then do the calculation.
You have to enter the value for miles, and THEN, AFTER that, you can calculate kilometers.
and when i test it, the result was still gibberish with a crazy exponential. could it be a compiler problem??? I thought maybe its coz im not initialising the variables so thats why i tested the earlier quoted version (with a lot of doubt) but then that didnt solve anything either, as noted duly
So in this code, you fetch a value for miles from the user, and then you change that value of miles using a value of kilometers that you did NOT fetch from the user (so it will be some random value), and then you output that random value of kilometers (and do nothing with the value of miles you calculated). So why are you surprised that it's some crazy random value?
Here is what you need to do:
Get value for miles from user.
Multiply that number by 1.609 (store this as kilometers).
Output kilometers.
Ok! so i switched line 5 and wrote it as such (thanks to your stern response); kilometers = 1.609 * miles instead of miles=1.609 * kilometers as shown above and guess what!!! IT WORKED. hehehe. ok i just thought that after declaring the variables, it wouldnt matter which side of the operator you place them , c++ would be able to understand. Guess my mistake was thinking a software was a human mind. THANKS ALOT Moschops...pizza on me- (as long as you can find ur way to Kenya). otherwise, thanks a bunch. I feel stupid, but more importantly, I've learnt.