1. TugaTech » Programação, Scripts e Webmasters » Programação, Scripts e Webmasters
Siga-nos

Realize o Login na sua conta ou Registe-se para participar.

Ver o tópico anterior Ver o tópico seguinte Ir para baixo  Mensagem [Página 1 de 1]

#1[Ajuda] Euromilhoes em c++ Empty [Ajuda] Euromilhoes em c++ - Seg 2 Jan 2012 - 9:29

DannyPt

Utilizador
DannyPt
eu tenho um trabalho para fazer em c++, o objectivo é recriar o jogo do euromilhões... só agora começou a complicar um bocado...
por exemplo, não estou a conseguir fazer para os numeros introduzidos não se repitam e que se organizem...
e nos numeros aleatórios a mesma coisa...
está aqui o enunciado do trabalho:
Enunciado

o meu trabalho até agora esta aqui:
Código:
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void main()
{
int K=0,estrelas[2],numeros[5],coluna,n,e,numero[5],estrela[2];
int i,j,aux;

char sair,opcao,rever;
HANDLE h;
do
{
   h= GetStdHandle ( STD_OUTPUT_HANDLE );
   SetConsoleTextAttribute( h , K+12 );
   printf("JOGO DO EUROMILHOES\n\n\n");
   SetConsoleTextAttribute( h , K+15 );
   printf("Seja bem vindo ao Jogo do Euromilhoes.\n\nComo Jogar:\n Seleccionam-se 5 numeros, que podem tomar valores de 1 a 50\n\n Seleccionam-se 2 estrelas, que podem tomar valores de 1 a 11\n\nDurante o sorteio, sao extraidos 5 numeros de 1 a 50 e duas estrelas que podem assumir valores de 1 a 11.\n\nO premio atribuido a cada jogador eh diferente consoante ah combinacao obtida de numeros/estrelas.\n\nA probabilidade de acertar na chave do primeiro premio no euromilhoes eh de 1 em 116 531 800\n\n\n");
   printf("Para efectuar uma jogada pressione uma das seguintes teclas\n");
   SetConsoleTextAttribute( h , K+158 );
   printf("  Para efectuar uma jogada aleatoria pressione a tecla [a/A]\n");
   SetConsoleTextAttribute( h , K+156 );
   printf("  Para efectuar uma jogada manual pressione a tecla [m/M]\n\n");
   SetConsoleTextAttribute( h , K+15 );
   scanf(" %c", &opcao);

   
//processo manual//
if((opcao!='a')&&(opcao!='A'))
   {
      printf("Voce escolheu a opcao manual.\nDe seguida escreva os numeroes e as estrelas pela ordem pedida\n\n");
      
      
      for (int i=0; i<5; i++)
      {
         do{
         SetConsoleTextAttribute( h , K+10 );
         printf("\nQual o %d numero? ", i+1);
         scanf_s(" %d", &numeros[i]);
         }while((numeros[i]<1)||(numeros[i]>50));
      }

      
   for (int j=0; j<2; j++)
      {
         do{
      SetConsoleTextAttribute( h , K+14 );
      printf("\nQual a %d estrela? ", j+1);
      scanf_s(" %d", &estrelas[j]);
      }while((estrelas[j]<1)||(estrelas[j]>11));
      }

      //ordenar estrelas//
   
   if(estrelas[0]>estrelas[1])
      {
         aux=estrelas[0];
         estrelas[0]=estrelas[1];
         estrelas[1]=aux;
      }

   //system("pause");

//ordernar numeros//

   for(i=0;i<5;i++)
      {
      for(j=0;j<4;j++)
         {
         if(numeros[j]>numeros[j+1])
            {
               aux=numeros[j];
               numeros[j]=numeros[j+1];
               numeros[j+1]=aux;
            }
         }
      }
   for(i=0;i<5;i++)
   {
      printf("O %d numero eh %d\n", i+1, numeros[i]);
   }
   
   for(j=0;j<2;j++)
   {
      printf("O %d estrela eh %d\n", j+1, estrelas[j]);
   }

   printf("\n\n");

   //matrizes//

   coluna=0;
   j=0;
   SetConsoleTextAttribute( h , K+141 );
   for (int i=1; i<51; i++)
      {
      if (numeros[j]==i)
         {
          SetConsoleTextAttribute( h , K+138 );
         printf( "    X");
         j++;
         SetConsoleTextAttribute( h , K+141 );
         }
      else
         {
          printf( " %4d", i);
         }
      coluna ++;
      if (coluna == 6)
         {
         printf("\n");
         coluna=0;
         }
      }
   printf("\n\n");
   coluna=0;
   j=0;
   SetConsoleTextAttribute( h , K+141 );
   for (int i=1; i<12; i++)
      {
      if (estrelas[j]==i)
         {
         if(j<2)
            {
   SetConsoleTextAttribute( h , K+142 );
    printf( "    X");
    j++;
    SetConsoleTextAttribute( h , K+141 );
    }
    else
    {
    continue;
    }
  }
        else
      {
    printf( " %4d", i);
  }
 
  coluna ++;
  if (coluna ==3)
  {
    printf("\n");
    coluna=0;
  }
 }
 printf("\n\n\n");
}

 //processo aleatório//
else{

   SetConsoleTextAttribute( h , K+15 );
 printf("Voce escolheu a opcao aleatoria.\nDe seguida irao ser produzidos 5 numeroes e 2 estrelas aleatorias\n\n");



printf("Os seus numeros sao:\n\n");
srand((unsigned)time(NULL));
for(n=1; n<=5; n++){

numero = rand()%51;

SetConsoleTextAttribute( h , K+13 );

printf("%d  ", numero);
SetConsoleTextAttribute( h , K+15 );


}
for(i=0;i<5;i++)
      {
      for(j=0;j<4;j++)
         {
         if(numero[j]>numero[j+1])
            {
               aux=numero[j];
               numero[j]=numero[j+1];
               numero[j+1]=aux;
            }
         }
      }
for(i=0;i<5;i++)
   {
      printf("O %d numero eh %d\n", i+1, numeros[i]);
   }

printf("\n\n");
SetConsoleTextAttribute( h , K+14 );
printf("As suas estrelas sao:\n\n");
srand((unsigned)time(NULL));
for(e=1; e<=2; e++){

estrela = rand()%12;

SetConsoleTextAttribute( h , K+14 );
printf("%d  ", estrela);
SetConsoleTextAttribute( h , K+15 );
}

if(estrela[0]>estrela[1])
      {
         aux=estrela[0];
         estrela[0]=estrela[1];
         estrela[1]=aux;
      }
for(j=0;j<2;j++)
   {
      printf("O %d estrela eh %d\n", j+1, estrela[j]);
   }

printf("\n\n");

}
//matrizes//
coluna=0;
   j=0;
   SetConsoleTextAttribute( h , K+141 );
   for (int i=1; i<51; i++)
      {
      if (numero[j]==i)
         {
          SetConsoleTextAttribute( h , K+138 );
         printf( "    X");
         j++;
         SetConsoleTextAttribute( h , K+141 );
         }
      else
         {
          printf( " %4d", i);
         }
      coluna ++;
      if (coluna == 6)
         {
         printf("\n");
         coluna=0;
         }
      }
   printf("\n\n");
   coluna=0;
   j=0;
   SetConsoleTextAttribute( h , K+141 );
   for (int i=1; i<12; i++)
      {
      if (estrela[j]==i)
         {
         if(j<2)
            {
   SetConsoleTextAttribute( h , K+142 );
    printf( "    X");
    j++;
    SetConsoleTextAttribute( h , K+141 );
    }
    else
    {
    continue;
    }
  }
        else
      {
    printf( " %4d", i);
  }
 
  coluna ++;
  if (coluna ==3)
  {
    printf("\n");
    coluna=0;
  }
 }
 printf("\n\n\n");





 //processo para rever os numeros e as estrelas//
SetConsoleTextAttribute( h , K+15 );
printf("Deseja rever os numero?[S/N]\n");
scanf_s(" %c", &rever);
if((rever!='s')&&(opcao!='s')){
   for(i=0;i<5;i++)
   {
      printf("O %d numero eh %d\n", i+1, numeros[i]);
   }
   printf("\n");
   for(j=0;j<2;j++)
   {
      printf("O %d estrela eh %d\n", j+1, estrelas[j]);
   }
}


 //processo para sair do programa//
SetConsoleTextAttribute( h , K+15 );
printf("\n\n");
 printf("Quer sair do programa? [S/N]\n");
 scanf(" %c", &sair);
 fflush(stdin);   
printf("\n\n\n");
}while((sair!='s')&&(sair!='S'));
SetConsoleTextAttribute( h , K+15 );
}

vou por tambem separado para verem cada processo
processo manual:
Código:
if((opcao!='a')&&(opcao!='A'))
   {
      printf("Voce escolheu a opcao manual.\nDe seguida escreva os numeroes e as estrelas pela ordem pedida\n\n");
      
      
      for (int i=0; i<5; i++)
      {
         do{
         SetConsoleTextAttribute( h , K+10 );
         printf("\nQual o %d numero? ", i+1);
         scanf_s(" %d", &numeros[i]);
         }while((numeros[i]<1)||(numeros[i]>50));
      }

      
   for (int j=0; j<2; j++)
      {
         do{
      SetConsoleTextAttribute( h , K+14 );
      printf("\nQual a %d estrela? ", j+1);
      scanf_s(" %d", &estrelas[j]);
      }while((estrelas[j]<1)||(estrelas[j]>11));
      }

      //ordenar estrelas//
   
   if(estrelas[0]>estrelas[1])
      {
         aux=estrelas[0];
         estrelas[0]=estrelas[1];
         estrelas[1]=aux;
      }

   //system("pause");

//ordernar numeros//

   for(i=0;i<5;i++)
      {
      for(j=0;j<4;j++)
         {
         if(numeros[j]>numeros[j+1])
            {
               aux=numeros[j];
               numeros[j]=numeros[j+1];
               numeros[j+1]=aux;
            }
         }
      }
   for(i=0;i<5;i++)
   {
      printf("O %d numero eh %d\n", i+1, numeros[i]);
   }
   
   for(j=0;j<2;j++)
   {
      printf("O %d estrela eh %d\n", j+1, estrelas[j]);
   }

   printf("\n\n");
processo automático:
Código:
//processo aleatório//
else{

   SetConsoleTextAttribute( h , K+15 );
 printf("Voce escolheu a opcao aleatoria.\nDe seguida irao ser produzidos 5 numeroes e 2 estrelas aleatorias\n\n");



printf("Os seus numeros sao:\n\n");
srand((unsigned)time(NULL));
for(n=1; n<=5; n++){

numero = rand()%51;

SetConsoleTextAttribute( h , K+13 );

printf("%d  ", numero);
SetConsoleTextAttribute( h , K+15 );


}
for(i=0;i<5;i++)
      {
      for(j=0;j<4;j++)
         {
         if(numero[j]>numero[j+1])
            {
               aux=numero[j];
               numero[j]=numero[j+1];
               numero[j+1]=aux;
            }
         }
      }
for(i=0;i<5;i++)
   {
      printf("O %d numero eh %d\n", i+1, numeros[i]);
   }

printf("\n\n");
SetConsoleTextAttribute( h , K+14 );
printf("As suas estrelas sao:\n\n");
srand((unsigned)time(NULL));
for(e=1; e<=2; e++){

estrela = rand()%12;

SetConsoleTextAttribute( h , K+14 );
printf("%d  ", estrela);
SetConsoleTextAttribute( h , K+15 );
}

if(estrela[0]>estrela[1])
      {
         aux=estrela[0];
         estrela[0]=estrela[1];
         estrela[1]=aux;
      }
for(j=0;j<2;j++)
   {
      printf("O %d estrela eh %d\n", j+1, estrela[j]);
   }

printf("\n\n");
criar matrizes:
Código:
//matrizes//

   coluna=0;
   j=0;
   SetConsoleTextAttribute( h , K+141 );
   for (int i=1; i<51; i++)
      {
      if (numeros[j]==i)
         {
          SetConsoleTextAttribute( h , K+138 );
         printf( "    X");
         j++;
         SetConsoleTextAttribute( h , K+141 );
         }
      else
         {
          printf( " %4d", i);
         }
      coluna ++;
      if (coluna == 6)
         {
         printf("\n");
         coluna=0;
         }
      }
   printf("\n\n");
   coluna=0;
   j=0;
   SetConsoleTextAttribute( h , K+141 );
   for (int i=1; i<12; i++)
      {
      if (estrelas[j]==i)
         {
         if(j<2)
            {
   SetConsoleTextAttribute( h , K+142 );
    printf( "    X");
    j++;
    SetConsoleTextAttribute( h , K+141 );
    }
    else
    {
    continue;
    }
  }
        else
      {
    printf( " %4d", i);
  }
 
  coluna ++;
  if (coluna ==3)
  {
    printf("\n");
    coluna=0;
  }
 }
 printf("\n\n\n");
}
se me poderem ajudar agradecia imenso, porque depois ainda vem a parte de leitura e escrita de um ficheiro e essa parte eu não percebo nada...

#2[Ajuda] Euromilhoes em c++ Empty Re: [Ajuda] Euromilhoes em c++ - Seg 2 Jan 2012 - 11:18

DJPRMF

Administrador
DJPRMF
Boas,
Bom, c++ não é propriamente a minha área... e o código, pelo que vejo, é um pouco complexo(e longo) para se ver algo assim "rápido". Smile

E também não percebi muito bem onde e/ou como se encontra a ter o problema. Smile


____________________________________________

[Ajuda] Euromilhoes em c++ Tugatechuserbar
[Ajuda] Euromilhoes em c++ 3
[Ajuda] Euromilhoes em c++ 2
TugaTech || Host TugaTech
https://tugatech.com.pt https://www.facebook.com/DJPRMF https://twitter.com/dj_prmf DJPRMF

Ver o tópico anterior Ver o tópico seguinte Ir para o topo  Mensagem [Página 1 de 1]

Permissões neste sub-fórum
Não podes responder a tópicos




Aplicações do TugaTechAplicações TugaTechDiscord do TugaTechDiscord do TugaTechRSS TugaTechRSS do TugaTechSpeedtest TugaTechSpeedtest TugatechHost TugaTechHost TugaTech