int main()
{
while(1)
{
system("cls");
switch(meniu())
{
case 49 : system("cls"); insert(); break;
case 50 : system("cls"); show(); system("pause"); break;
case 51 : system("cls"); show(Media(0),0); system("pause"); break;
case 52 : system("cls"); show(Media(1),1); system("pause"); break;
case 53 : system("cls"); find(); system("pause"); break;
case 54 : system("cls"); findgroup(); system("pause"); break;
case 55 : system("cls"); findmedia(); system("pause"); break;
case 56 : system("cls"); sort(); system("pause"); break;
case 57 : system("cls"); sortmedia(); system("pause"); break;
case ? : system("cls"); sortgen(); system("pause"); break;
case 27 : exit(0);
}
}
return 0;
}
what would be the case nr. after the 57 one? (which should be 10)
how do I represent it?
I though of giving the choice for user to press a letter instead of a number, but i am convinced there is a way to reproduce number 10.
If you really want the user to enter 10 as chars - and still return a char, then meniu() will need to be able to accept 10 as a string input and convert to say : which can then be used as a case statement.
#define CLS system("cls")
#define PAUSE system("pause")
int main()
{
while (1)
{
CLS;
switch (meniu())
{
case 49: CLS; insert(); break;
case 50: CLS; show(); PAUSE; break;
case 51: system("cls"); show(Media(0), 0); system("pause"); break;
case 52: system("cls"); show(Media(1), 1); system("pause"); break;
case 53: system("cls"); find(); system("pause"); break;
case 54: system("cls"); findgroup(); system("pause"); break;
case 55: system("cls"); findmedia(); system("pause"); break;
case 56: system("cls"); sort(); system("pause"); break;
case 57: system("cls"); sortmedia(); system("pause"); break;
case 10 : system("cls"); sortgen(); system("pause"); break;
case 27: exit(0);
}
}
return 0;
}
Watch your indenting.
The space between "case" and the number is unnecessary, but if you have a reason it does not matter. The compiler will just ignore the spaces.
coder777's example of using 10 can work, but it would depend on what the "meniu" function returns. Without seeing the "meniu" function it is hard to advise on what to do not knowing what it returns.
The "#defines", maybe not the best choice is a way to make the code a little cleaner. Use if you like.
As per seeplus's example I have found that when menu choices exceed the number 9 it is better to use letters. And if you consider upper case and lower case as separate you can have 52 choices.