I've been trying to figure this "finish the code" section on this online book i am doing. and for some reason i am at a lost. the program allows you to convert units given from a user to another unit also given from the user with a value applied. so for example a user will say he wants to convert from cm to inches and gives a value of say 10 and the program will output 10 cm = 3.93701 in.
Line 53 outputs what the user just inputted, so it appears twice without reason.
Moreover, you should output a statement telling the user to input a value before line 78, otherwise the user is just staring at the console and has to figure it out for themselves.
Be sure to change only what is what's marked with ". . . " in the original. So you should delete lines 71 and 83-86.
The if at your line 73 should check whether you have two valid units. You can do that by checking whether both factor1 and factor2 are non-zero.
Hmm. Actually the code has bugs that require changes other than what's in ". . ." If you go through the loop a second time and enter an invalid unit, factor1 will still contain the non-zero value from the first time through the loop.
To fix this, factor1 and factor2 should be set to zero inside the while loop:
1 2 3 4 5
while (!done)
{
double factor1 = 0; // conversion factor from first unit to cm
double factor2 = 0; // conversion factor from cm to second unit
bool again = false; // true to repeat the same conversion