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
251 views
in Review of C++ Programming by (30.5k points)
closed by

Rewrite the above code using if else if ladder.

#include 

using namespace std; 

int main()

{

int n;

cout<<"Enter a number in between 1-7";

cin>>n;

switch(n)

{

case 1: cout<< "Sunday";break;

case 2: cout<< "Monday";break;

case 3: cout<< "Tuesday";break;

case 4: cout<< "Wednesday";break;

case 5: cout<< "Thursday";break;

case 6: cout<< "Friday";break;

case 7: cout<< "Saturday";break;

default : cout<<"Invalid"

}

}

1 Answer

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

#include 

using namespace std; 

int main()

{

int n;

cout<<"Enter a number in between 1-7:";

cin>>n;

if(n==1)

cout<< "Sunday";

else if(n==2)

 cout<< "Monday";

else if(n==3)

cout<< "Tuesday";

else if(n==4)

cout<< "Wednesday";

else if(n==5)

cout<< "Thursday";

else if(n==6)

cout<< "Friday";

else if(n==7)

cout<< "Saturday";

else

cout<<"Invalid";

}

}

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

...