zedealges Posted November 29, 2007 at 07:05 PM Report Share #151192 Posted November 29, 2007 at 07:05 PM Boas, para este periodo tenho como projecto programar o jogo do tetris em C++ já tenho algum código mas ainda está longe de estar completo, mas dá-me alguns erros que não consigo resolver =/.. quando faço build não detecta os erros e diz 1 succeed como é suposto, mas depois faço executar, e ainda depois de introduzir os valores é que diz que a variável retorno não é declarada =/, até já experimentei pôr como varável global e deu o mesmo.. senão for muito cansativo, agradecia que dessem uma vista de olhos ao código lol se quiserem, estou a programá-lo com funções #include <iostream> #include <conio.h> using namespace std; void menu( void ); int tratarmenu( char op ); int nivel( int nl ); int main() { char op; int k = 0; do { menu(); cin >> op; op = toupper(op); k = tratarmenu( op ); } while( k == 0 ); } void menu( void ) { cout << "Seleccione uma opção:" << endl; cout << "J: Jogar." << endl; cout << "N: Nível de dificuldade do jogo." << endl; cout << "P: Pontuação." << endl; cout << endl; cout << "S: Sair do jogo." << endl; } int tratarmenu( char op ) { char sd; int retorno, oc; switch(op) { case 'J': { break; } case 'N': { oc = nivel(op); break; } case 'P': { break; } case 'S': { do { cout << "Deseja sair do jogo? (y/n)" << endl; cin >> sd; sd=toupper(sd); if( sd == 'Y' ) { retorno = 1; } else if( sd == 'N' ) { retorno = 0; } else { cout << "Opção não reconhecida!" << endl; } } while(sd!='Y' && sd !='N'); break; } default: { cout << "Opção inválida!" << endl; } } return retorno; } int nivel( int nl ) { cout << "Escolha um nível de dificuldade:" << endl; cout << " - 1" << endl; cout << " - 2" << endl; cout << " - 3" << endl; cout << " - 4" << endl; cout << " - 5" << endl; cin >> nl; return nl; } Beijinhos lá para a Mulher. Link to comment Share on other sites More sharing options...
mobes Posted November 29, 2007 at 09:18 PM Report Share #151230 Posted November 29, 2007 at 09:18 PM As tuas variáveis não foram inicializadas... e como não afectas a variável retorno quando escolhes J ,N ou P, dá barraca. Com int retorno = 0, oc=0; já não te chateia com o retorno...ainda não faz é nada 😉 Link to comment Share on other sites More sharing options...
zedealges Posted November 29, 2007 at 09:39 PM Author Report Share #151236 Posted November 29, 2007 at 09:39 PM então tudo o que tenho de fazer é atribuir logo um valor? mas isso não vai afectar as opções pois não? EDIT: já testei e está resolvido, obrigado 😉 Beijinhos lá para a Mulher. Link to comment Share on other sites More sharing options...
mobes Posted November 29, 2007 at 10:03 PM Report Share #151246 Posted November 29, 2007 at 10:03 PM Ora... só te disse que aquilo estoira por não estares a iniciar a variável retorno. Se tiveres a certeza que em todas as opções afectas o retorno... não haverá esse problema 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now