Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
i need a way to make this code work regarding switch

i cannot make the cout appear within my switch, i hope someone here could help me

this is the code given to me, aslo please if possible the simplest way of work around, thanks

#include <iostream>

using namespace std;

int main() {
    double fh, cs;

    cout << "Enter Fahrenheit: ";
    cin >> fh;

    cs = (fh - 32) * 5 / 9;
    cout << "Temperature in Celsius: " << cs;

    switch (cs < 40)
    {
    case 1:
        switch (cs <= 0) {
        case 1:
            cout << "\nFreezing weather";
            break;
        }
        break;
    case 2:
        switch ((cs >= 1) < 10) {
        case 1:
            cout << "\nVery Cold weather";
            break;
        }
    case 3:
        switch ((cs >= 11) < 20) {
        case 1:
            cout << "\nCold weather";
            break;
        }
    case 4:
        switch ((cs >= 21) < 30) {
        case 1:
            cout << "\nNormal in Temp";
            break;
        }
    case 5:
        switch ((cs >= 31) < 40) {
        case 1:
            cout << "\nIt's Hot";
            break;
        }


    case 0:
        cout << "\nIt's Very Hot";
        break;
    }

    return 0;
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

the outter switch cs < 40 you can only get 0 if cs >= 40 or 1 if cs < 40, you can not get other cases like 2,3,4,5. Why not just use if statement.

over 4 years ago · Santiago Trujillo Denunciar

0

You are using switch the wrong way. Each of the expression written under switch will only evaluate to 0 or 1. So other cases are not reachable. What you are trying to do can be better achieved with if/else.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda