'good day i need tips on how to work around this problem

Write a C++ program using switch-case that would ask the user to type a temperature in Fahrenheit then will be converted by the program in Celsius and will display a suitable message according to temperature state below:

Temp < 0 then Freezing weather

Temp 1-10 then Very Cold weather

Temp 11-20 then Cold weather

Temp 21-30 then Normal in Temp

Temp 31-40 then Its Hot

Temp >=40 then Its Very Hot

i can work around the conversion process, but i cannot understand how to implement it using switch case,



Solution 1:[1]

switch-case can accept only expression and result of this expression. You can do it in a bit bulky way. But keep in mind that this style is low-readable and actually you'd better use simple if else constructions.

#include <iostream>
using namespace std;

int main()
{
    int temperature;
    cin >> temperature;
    switch(temperature)
    {
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
        case 7:
        case 8:
        case 9:
        case 10:
            cout << "Very cold";
            break;
        case 11:
        case 12:
        case 13:
        case 14:
        case 15:
        case 16:
        case 17:
        case 18:
        case 19:
        case 20:
            cout << "Cold";
            break;
        case 21:
        case 22:
        case 23:
        case 24:
        case 25:
        case 26:
        case 27:
        case 28:
        case 29:
        case 30:
            cout << "Normal";
            break;
        case 31:
        case 32:
        case 33:
        case 34:
        case 35:
        case 36:
        case 37:
        case 38:
        case 39:
        case 40:
            cout << "Hot";
            break;
        default:
            if(temperature<0)
                cout << "Freezing";
            if(temperature>=40)
                cout << "Very hot";
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 korzck