Help compiles but dosen't work??

well after several days researching I managed to get this to compile but I have a problem it doesn’t work. It is my first effort with a string so that is where to start looking but I can't find a error? Would this be a logic error? The output is not complete I know.

Thank you in advance for your help,
Randy

This program would convert units from English (US) to metric

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 /*
* 020947X APR 2014
* Randy Williamson
* Practical C++ Programing O'Reily book
* chapter 7-1
*/


#include <iostream>
#include <string>


// TODO (randy#1#): solve logic error
int main()
{
    /* declorations of variables */

    double const Miles_2_Kilometers = 1.609;
    double const Gallon_2_Liters = 3.785;
    double const Feet_2_Meters = 0.3048;
    double const Pound_2_Kilograms = 2.2046;

    double numeric_value = 0; // userinput value
    double result = 0; // output value to terminal
    std::string unit; // user input choice


   /* Input with instructions */

    std::cout << "Enter a choice: mile, gallon, feet. or pound " << '\n'; // instructions to user
    std::getline(std::cin, unit); // input from user
    std::cout << "Enter how many units to convert" << '\n'; // instructions to user
    std::cin >> numeric_value; // input from user

    /* Alternation Object Area */

    if (unit.compare("mile") == 0);{
        result = numeric_value / Miles_2_Kilometers;
    }
    if (unit.compare("gallon") == 0); {
        result = numeric_value / Gallon_2_Liters;
    }

    if (unit.compare("feet") == 0); {
        result = numeric_value * Feet_2_Meters;
    }

    if (unit.compare("pound") == 0 ); {
        result = numeric_value * Pound_2_Kilograms;
    }


    /* output to user terminal*/

    std::cout << "The results are " << unit << " equal " << result;


    return 0;
}
There shouldn't be a semicolon after your ifs:
1
2
3
if (unit == "mile") { // No semicolon, and you can just compare with ==
    result = numeric_value / Miles_2_Kilometers;
}
Thank you
Topic archived. No new replies allowed.