+ 5
Does it possible to use multiple switch?
int main(){ switch(){} switch(){}}
19 odpowiedzi
+ 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. :>
+ 8
Oh LOL you're welcomed xD
Nice program btw.
+ 7
Can I take a look at your code?
+ 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?
+ 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;
}
+ 5
wow that's a good program......
+ 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;
}
+ 4
you are genius, i just know about array now. LOL thanks..
+ 3
already fixed, i only missed a '<' in cout<<lnm<endl; at the bottom of the code. thanks a lot for your help. 👍
+ 2
Yes we can use multiple switch statement
+ 1
yes, you can use multiple switch statement
+ 1
yes we can use multiple switch
0
yes
0
we can use it
0
yes
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.
0
Yeah we can surely use it
0
yes we can use switch statement again and again in any function
- 1
Please finish the course first, then ask.