Jump to content

ajuda com menu e submenu


pestynha

Recommended Posts

fiz este pedaço de codigo anexo em baixo .

o que quero que ele faça a seguir é quando entrar no menu 1 apresente regras e possibilite voltar ao menu anterior .

outra coisa o programa ta a sair quando se da 2 enters qual a soluçao ?

obrigado

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

main()
{


}
Edited by pestynha
Adicionei GeSHi e indentacao
Link to comment
Share on other sites

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Edited by pikax

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Link to comment
Share on other sites

Nao te falta um while algures no codigo?

Sem um ciclo, o programa nao repete nada.

Edited by pmg

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Link to comment
Share on other sites

penso que nao seja esse while

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Link to comment
Share on other sites

Porque nao algo como:

#define MENU    "[1]regras\n [2]jogo\n[3]Sair\n"
#define SUBMENU   "[1] voltar ao menu anterior\n[2]Sair\n"
void menuPrincipal(){
 char opcao;
 do{
      printf(MENU);
      scanf(" %c", &opcao);
      switch(opcao){
            case 1: submenu();
                         break;
            case 2: initjogo();
                         break;
            case 3: exit(0);
                         break;
            default: printf("opcao invalida");
  } while(opcao != 3);
}
void submenu(){
  char opcao;
do{
    printf(SUBMENU);
    scanf(" %c", &opcao);
    switch(opcao){
     case 1: menu_principal();
                  break;
     case 2: exit(1);
                  break;
     default: printf("opcao invalida");
     }
 }while(opcao != 2);
}
int main(char argc, **char argv){
    menu_principal();
}
Edited by mundo
Link to comment
Share on other sites

io pessoal ja fiz o sub menus mas tou com um problema nao volta ao principal

vou postar o ficheiro com o codigo

peço desculpa nao consegui meter as corzinhas

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
void MenuPrincipal(void);
int submenu(void);
void galo (void);
int main (void)
  }while(resp=='s' || resp=='S');
}
}
Edited by pestynha
Link to comment
Share on other sites

peço desculpa nao consegui meter as corzinhas

substitui o [ CODE] por [ CODE=C] (mas sem o espaco)

  • Vote 1

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Link to comment
Share on other sites

ola sou novo aqui queria saber como fazer um stwich como este?

obrigado....percebo alguma coisa de programação

http://img831.images.../capturarri.jpg

como assim???

Nao sabes fazer um switch e queres fazer algo assim em C? :O

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Link to comment
Share on other sites

LOL??

ve se este link te ajuda http://www.portugal-a-programar.pt/guidelines/

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Link to comment
Share on other sites

Basicamente, um switch, é como se fosse um conjunto de condições. Mas em vez de teres:

if (a == 1) {
   // faz 1
}
else if (a == 2) {
   // faz 2
}
else if (a == 3) {
   // faz 3
}
else {
   // faz outro
}

Fazes:

switch (a) {
   case 1:
       // faz 1
       break;
   case 2:
       // faz 1
       break;
   case 3:
       // faz 1
       break;
   default:
       // faz outro

Lembra-te de colocar o break, caso contrário, todos os casos que estão a baixo são executados.

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.