Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!