Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda