Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
232 views
in Review of C++ Programming by (30.5k points)
closed by

Consider the following code

# include using namespace std; 

int main()

{

int mark;

 cout<<"Enter a mark";

cin>>mark;

if (mark>=75)

     cout<<"Distinction";

else if (mark>=60)

        cout<<"First class";

else if (mark>=50)

        cout<<"Second class";

else if (mark>=40)

       cout<<"passed";

else

      cout<<"Failed";

}

Is it possible to rewrite the above program using switch statement? Distinguish between switch and if else if ladder. 

1 Answer

+1 vote
by (30.4k points)
selected by
 
Best answer

No. It is not possible to write the above code using switch statement.

Following are the difference between switch and if else if ladder. 

1. Switch can test only for equality but if can evaluate a relational or logical expression 

2. If else is more versatile 

3. If else can handle floating values but switch can not 

4. If the test expression contains more variable if else is used 

5. Testing a value against a set of constants switch is more efficient than if else

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...