Menu

Help needed - Conversions not working

2015-10-14
2016-03-21
  • Dominic McGrath

    Dominic McGrath - 2015-10-14

    include "iostream"

    include <windows.h>

    using namespace std;

    int main()
    {
    int option;

    cout << "Welcome to the converter\n";
    cout << "Please select function you would like to convert;\n";
    cout << "1 - Degrees Fahrenheit to Celsius;\n";
    cout << "2 - Inches to centimeters;\n";
    cout << "3 - Pound to Stones.\n";
    cout << "Please enter the digit here : ";
    
    cin >> option;
    
    switch(digit);
        {
            case '1' :
                cout << "Please enter your Fahrenheit degrees here : ";
                cin >> number;
                answer = (number - 1) * .5556;
                cout << "Fahrenheit converted to Celsius : " << answer;
                break;
    
            case '2' :
                cout << "Please enter the amount of inches here : ";
                cin >> number;
                answer = number * 2.54;
                cout << "Inches converted to centimeters : " << answer;
                break;
    
            case '3' :
                cout << "Please enter the amount of pounds here : ";
                cin >> number;
                answer = number * 14;
                cout << "Pounds converted to stones : " << answer;
                break;
        }
    return 0;
    

    }

     
  • Tarquin Delfino

    Tarquin Delfino - 2016-03-21

    the following code works

    #include <iostream>
    // use < > round iostream
    
    using namespace std;
    
    int main()
    {
    int option;
    int number;
    float answer;
    
    // define all variables number and answer
    
    cout << "Welcome to the converter\n";
    cout << "Please select function you would like to convert;\n";
    cout << "1 - Degrees Fahrenheit to Celsius;\n";
    cout << "2 - Inches to centimeters;\n";
    cout << "3 - Pound to Stones.\n";
    cout << "Please enter the digit here : ";
    
    cin >> option;
    
    // use "option" not "digit"
    // do not end the switch with a ";"
    switch(option)
    {
    
        case 1 :
        // remove single quotes from each 'number' we test for the value
        // not a string
            cout << "Please enter your Fahrenheit degrees here : ";
            cin >> number;
            answer = (number - 32) * 5/9;
            // corrected the formula
            cout << "Fahrenheit converted to Celsius : " << answer;
        break;
    
        case 2 :
            cout << "Please enter the amount of inches here : ";
            cin >> number;
            // define answer as a float (see above)
            answer = number * 2.54;
            cout << "Inches converted to centimeters : " << answer;
        break;
    
        case 3 :
            cout << "Please enter the amount of pounds here : ";
            cin >> number;
            answer = number * 14;
            cout << "Pounds converted to stones : " << answer;
        break;
    }
    return 0;
    
    }
    
     

    Last edit: Tarquin Delfino 2016-03-21

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.