switch char/string imbriqués C++
Bonjour,
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
//switch avec char/string en C++ inbriqués
//cette version marche
//-----version simple
#include <iostream>
#include <string>
using namespace std;
int zer;
//int main()
//{
//cout<<"choix a ou b"<<endl;
//char sw;
//sw=getchar();
//switch (sw)
// {
// case 'a':
// {
// cout<<"section a"<<endl;break;
// }
// case'b':
// {
// cout<<"section b"<<endl;break;
// }
// default:{cout<<"defo a b"<<endl;break;}
// }
//return 0;
//cout<<"0/q"<<endl;
//cin>>zer;
//}
//-----version simple fin |
//=====version imbriquées ne marche pas!pourquoi?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
int main()
{
cout<<"choix a ou b"<<endl;
char sw;
sw=getchar();
switch (sw)
{//sw ab
case 'a':
{//sw a
cout<<"section a"<<endl;
cout<<"choix x ou y (fils de section a)"<<endl;
char sw;//facultatif(?) pour mise à zéro de sw??
sw=getchar();
switch(sw)
{//sw xy
case 'x':
{//x
cout <<"x/a"<<endl;break;
}//x
case 'y':
{//y
cout <<"y/a"<<endl;break;
}//y
default:{cout<<" defo x y"<<endl;}
}//sw xy
}//sw a
break;
case'b':
{//sw b
cout<<"section b"<<endl;break;
}//sw b
default:{cout<<"defo a b NE DEVRAIT PAS APPARAITRE!"<<endl;}
}//sw ab
//return 0;
cout<<"0/q"<<endl;
cin>>zer;
}
//===version imbriquée fin |
Merci.