string comparison in if statement help

I am trying to write a program that can take two different kind of inputs for units but the output must always be in kg. I am able to run the code but the if statement never takes place.
[code]


double Weight;
string UNITS;


cout << "Enter Weight and Units, separated by a space:";
cin >> Weight;
cin >> UNITS;

if (UNITS == "g")
Weight / 1000 ;
cout << "your weight is " << Weight << "in kg.";
1
2
3
if (UNITS == "g")
Weight / 1000;
cout << "your weight is " << Weight << "in kg.";


I would recommend to declare a variable that would save the computation Weight / 1000;

something like...
1
2
3
4
5
double unitsInkg = 0.0; // Declare and initialize the variable.
//blah, blah, blah//
if (UNITS == "g")
unitsInkg = Weight / 1000 ;
cout << "your weight is " << unitsInkg << "in kg."; 
Topic archived. No new replies allowed.