Does it possible to use multiple switch? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 5

Does it possible to use multiple switch?

int main(){ switch(){} switch(){}}

17th Jan 2017, 4:27 AM
HendryAce
HendryAce - avatar
19 Antworten
+ 14
Yes. You can use multiple switch statements. Heck, you can even nest them to achieve switchceptions. However, nested switch statements are harder to maintain. :>
17th Jan 2017, 4:33 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
Oh LOL you're welcomed xD Nice program btw.
17th Jan 2017, 5:09 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Can I take a look at your code?
17th Jan 2017, 4:44 AM
Hatsy Rei
Hatsy Rei - avatar
+ 7
I have not identified any error inside your code after porting it to desktop compiler. Can you tell me what error message is printed by the compiler?
17th Jan 2017, 5:06 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
P.S. The easier way to do the first part of your code would perhaps be to replace the entire switch statement with an array. Works similarly with less lines. #include <iostream> using namespace std; int main() { int thns = 2017; int thnt = 0; int htg = 10; string zch; string zodiac_array[12] = {"Mouse", "Cow", "Tiger", "Bunny", "Dragon", "Snake", "Horse", "Goat", "Monkey", "Chicken", "Dog", "Pig"}; cout << "Please input your year of birth : "; cin >> thnt; while (thns > thnt) { if (htg == 1) { htg = 12; } else { htg--; } thns--; } zch = zodiac_array[htg - 1]; cout << "Your chinese zodiac is " << zch << endl; cout << "Your current age: " << 2017 - thnt << " years" << endl; return 0; }
17th Jan 2017, 5:16 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
wow that's a good program......
17th Jan 2017, 11:49 AM
Leon lit
Leon lit - avatar
+ 4
#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { int thns, thnt, htg, hhg; string zch, lnm; thns= 2017; htg=10; thnt=0; cin>>thnt; //input year while(thns>thnt) { thns--; if(htg==1) { htg=12; } else { htg--; } } //Counting years switch(htg) { case 1 : zch="Mouse"; break; case 2 : zch="Cow"; break; case 3 : zch="Tiger"; break; case 4 : zch="Bunny"; break; case 5 : zch="Dragon"; break; case 6 : zch="Snake"; break; case 7 : zch="Horse"; break; case 8 : zch="Goat"; break; case 9 : zch="Monkey"; break; case 10 : zch="Chicken"; break; case 11 : zch="Dog"; break; case 12 : zch="Pig"; break; default : zch="Invalid input"; break; } //Output aliasing from integer to string cout<<"Your chinesse zodiac is: "<<zch<<endl<<"You was born in: "<<thnt<<endl<<"Your current age: "<<2017-thnt<<" "<<"years"<<endl; //Print out the basic output hhg=htg; switch(hhg) { case 1 : lnm="This year will bring you a big lucky, you will meet your love (for whom that are single) in May and July, you will not need to be worry on your economy, whatever you are in a poor condition, this year will bring you a great lucky, you may be promoted in this year"; break; default : lnm=" ------------------"; } cout<<lnm<endl; }
17th Jan 2017, 4:49 AM
HendryAce
HendryAce - avatar
+ 4
you are genius, i just know about array now. LOL thanks..
17th Jan 2017, 5:17 AM
HendryAce
HendryAce - avatar
+ 3
already fixed, i only missed a '<' in cout<<lnm<endl; at the bottom of the code. thanks a lot for your help. 👍
17th Jan 2017, 5:09 AM
HendryAce
HendryAce - avatar
+ 2
Yes we can use multiple switch statement
18th Jan 2017, 3:38 PM
Ashutosh Saraf
Ashutosh Saraf - avatar
+ 1
yes, you can use multiple switch statement
19th Jan 2017, 7:00 AM
Zeus92
+ 1
yes we can use multiple switch
19th Jan 2017, 7:42 PM
Shalini Dubey
Shalini Dubey - avatar
0
yes
18th Jan 2017, 6:09 PM
Akshay Kumar
Akshay Kumar - avatar
0
we can use it
18th Jan 2017, 6:25 PM
PETER MGIMWA
PETER MGIMWA - avatar
0
yes
19th Jan 2017, 1:51 PM
Ritik Jaiswal
Ritik Jaiswal - avatar
0
yes, we can because the java is a language which was made under such speciality that none can point out his mistakes though there not a mistake and every advantage has given to us that we can develop any coding at any time without any restrictions.
19th Jan 2017, 4:04 PM
Chitrang Kumar Jain
Chitrang Kumar Jain - avatar
0
Yeah we can surely use it
19th Jan 2017, 5:59 PM
Harsh Jain
Harsh Jain - avatar
0
yes we can use switch statement again and again in any function
18th Feb 2017, 10:21 AM
Nomi Numan
Nomi Numan - avatar
- 1
Please finish the course first, then ask.
18th Jan 2017, 12:17 PM
Maksym Zieliński
Maksym Zieliński - avatar