Ir ao conteúdo

SantosRodrigues00

Membro Júnior
  • Posts

    4
  • Cadastrado em

  • Última visita

Tudo que SantosRodrigues00 postou

  1. Conseguiiii, muito obrigada pelas respostas
  2. Obrigada por responder, fiz a mudança do main, mas continua o erro. já não sei mais o que fazer
  3. Gente, fiz esse jogo de adivinhação, e preciso que ele guarde os números digitados, caso o jogador saia. Esta dando um erro que não consigo descobrir, e tenho que apresentar amanhã, se alguém puder ajudar agradeço. #include <stdio.h> #include <time.h> int main(void) { char url[]="char.txt"; char ch; FILE *arq; printf("num: "); ch=getchar(); arq = fopen(url, "w"); if(arq == NULL) printf("Erro, nao foi possivel abrir o arquivo\n"); else{ fputc(ch, arq); fclose(arq); } return 0; } int random(); void dicas(int num, int password, int tentativas); int main() { int continuar=1, password, tentativas, num; do { system("cls || clear"); printf("Sorteando numero entre 1 e 1000...\n"); password = random(); printf("Comecou! Tente adivinhar o numero!\n\n"); tentativas = 0; do { tentativas++; printf("Tentativa %d: ", tentativas); scanf("%d", &num); dicas(num,password,tentativas); } while( num != password); printf("Digite 0 para sair, ou qualquer outro numero para continuar: "); scanf("%d", &continuar); } while(continuar); } int random() { srand( (unsigned)time(NULL) ); return (1 + rand()%1000); } void dicas(int num, int password, int tentativas) { if(num > password) printf("O numero sorteado e menor que %d\n\n", num); else if(num < password) printf("O numero sorteado e maior que %d\n\n", num); else printf("Parabens! voce acertou o numero em %d tentativas!\n\n", tentativas); }
  4. Olá, pessoal preciso de um help. tenho um jogo da velha já pronto, bem simples. mas agora preciso que ele guarde as informações, e não estou conseguindo a solução. implementar o jogo da velha com a possibilidade de parar a qualquer momento. e depois recomeçar quando desejar, fazer com arquivo texto ou binário Segue o código: #include <stdio.h> #include <stdlib.h> char tela[3][3]; int i, j, x, y, teste=1, pl, velha=0; void display(void); void teste_trinca(int pl); void play1(void); void play2(void); int main() {//abre main() for(i=0;i<3;i++)//for1 for(j=0;j<3;j++)//for2 tela[i][j]=' '; while(teste!=0)//while1 {//abre while teste if(teste!=0) {//abre if play1 play1(); if(tela[x][y]==' ')//if menor {//abre if menor tela[x][y]='X'; system("cls"); velha++; teste_trinca(pl); }//fecha if menor else { system("cls"); printf("já esta sendo usada essa possisao!!\n"); system("cls"); play1(); } }//fecha if play1 if(teste!=0) {//abre if play2 play2(); if(tela[x][y]==' ') { velha++; tela[x][y]='O'; system("cls"); teste_trinca(pl); } else { system("cls"); printf("já esta sendo usada essa possisao!!\n"); system("cls"); play2(); } }//fecha if play }//fecha while teste }//fecha main() void display(void) {//abre tela() printf(" 1 2 3 Y\n"); printf(" 1 %c | %c | %c \n",tela[0][0],tela[0][1],tela[0][2]); printf(" ---|---|--- \n "); printf("2 %c | %c | %c \n",tela[1][0],tela[1][1],tela[1][2]); printf(" ---|---|--- \n "); printf("3 %c | %c | %c \n",tela[2][0],tela[2][1],tela[2][2]); printf("X\n"); }//fecha tela() void teste_trinca(int pl) {//abre teste /*-------------TESTA NA HORIZONTAL--------*/ if(x==0) if((tela[0][0]==tela[0][1]) && (tela[0][1]==tela[0][2])) {//if1 display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; }//if1 if(x==1) if((tela[1][0]==tela[1][1]) && (tela[1][1]==tela[1][2])) {//if2 display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; }//if2 if(x==2) if((tela[2][0]==tela[2][1]) && (tela[2][1]==tela[2][2])) {//if3 display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; }//if3 /*----------TESTA NA VERTICAL--------*/ if(y==0) if((tela[0][0]==tela[1][0]) && (tela[1][0]==tela[2][0])) {//if1 display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; }//if1 if(y==1) if((tela[0][1]==tela[1][1]) && (tela[1][1]==tela[2][1])) {//if2 display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; }//if2 if(y==2) if((tela[0][2]==tela[1][2]) && (tela[1][2]==tela[2][2])) {//if3 display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; }//if3 if(((x==0)&&(y==0))||((x==1)&&(y==1))||((x==2)&&(y==2))) { if((tela[0][0]==tela[1][1]) && (tela[0][0]==tela[2][2])) { display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; } } if(((x==0)&&(y==2))||((x==1)&&(y==1))||((x==2)&&(y==0))) { if((tela[0][2]==tela[1][1]) && (tela[0][2]==tela[2][0])) { display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; } } /*----------TESTA NA DIAGONAL--------*/ else if(tela[0][0] == tela[1][1] && tela[1][1] == tela[2][2] && tela[0][0] != ' ') { display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; } else if(tela[2][0] == tela[1][1] && tela[1][1] == tela[0][2] && tela[2][0] != ' ') { display(); printf("JOGADOR **%i** GANHOU!! \n",pl); teste=0; } }//fecha teste void play1(void) {//abre play1 display(); printf("Jogador 1: Digite a coordenada **X**: "); scanf("%i",&x); printf("Jogador 1: Digite a coordenada **Y**: "); scanf("%i",&y); pl=1; x--; y--; }//fecha play1 void play2(void) {//abre play2 display(); printf("Jogador 2: Digite a coordenada **X**: "); scanf("%i",&x); printf("Jogador 2: Digite a coordenada **Y**: "); scanf("%i",&y); pl=2; x--; y--; }//fecha play2

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

LANÇAMENTO!

eletronica2025-popup.jpg


CLIQUE AQUI E BAIXE AGORA MESMO!