Simplificar Código... duvida!

09/06/2008

0

Bom dia pessoal,

Fiz um programa abaixo que permitir a leitura dos placares de cada set de uma partida de Vôlei! Caso o placar do set seja inválido, o programa deverá descartá-lo e solicitar uma nova digitação, até que o usuário defina um placar válido. O programa encerra quando uma equipe for a vencedora do confronto, ou seja, vencer três sets.
Porem achei o meu código muito extenso e gostaria de saber se alguém poderia me dar uma dica para simplificá-lo um pouco???

# include <stdio.h>
include <conio.h>
main ()
{


int set,cont,timea,timeb,vita,vitb,aux;

set=0;
cont=0;
timea=0;
timeb=0;
vita=0;
vitb=0;
aux=0;


while ((vita<3) && (vitb<3))
{
aux=0;

set++;
printf (´\nSET ¬d \n\n\n´, set);
printf (´PONTOS DO TIME A \n´);
scanf (´¬d´,&timea);
printf (´PONTOS DO TIME B \n´);
scanf (´¬d´,&timeb);



while (aux==0)
{
if (timea>timeb)
{
if(((timea-timeb)!=2) || (timea<25))
{

if((timea==25) && ((timea-timeb)>=2))
{
aux++;
}
else
{
aux=0;
printf (´\nINVALIDO\n´);
printf (´PONTOS DO TIME A \n´);
scanf (´¬d´,&timea);
printf (´PONTOS DO TIME B \n´);
scanf (´¬d´,&timeb);
}


}
else
aux++;



}

if (timeb>timea)
{

{
if(((timeb-timea)!=2) || (timeb<25))
{

if((timeb==25) && ((timeb-timea)>=2))
{
aux++;
}
else
{
aux=0;
printf (´\nINVALIDO\n´);
printf (´PONTOS DO TIME A \n´);
scanf (´¬d´,&timea);
printf (´PONTOS DO TIME B \n´);
scanf (´¬d´,&timeb);
}


}
else
aux++;


}




}
}

if(timea>timeb)
vita++;
if(timeb>timea)
vitb++;


//----------------------------- TAILBRAKE ------------------------------------


while ((vita==2) && (vitb==2))
{
aux=0;

set++;
printf (´\nSET DECISIVO (TAILBRAKE) \n\n\n´);
printf (´PONTOS DO TIME A \n´);
scanf (´¬d´,&timea);
printf (´PONTOS DO TIME B \n´);
scanf (´¬d´,&timeb);


while (aux==0)
{
if (timea>timeb)
{
if(((timea-timeb)!=2) || (timea<15))
{

if((timea==15) && ((timea-timeb)>=2))
{
aux++;
}
else
{
aux=0;
printf (´\nINVALIDO\n´);
printf (´PONTOS DO TIME A \n´);
scanf (´¬d´,&timea);
printf (´PONTOS DO TIME B \n´);
scanf (´¬d´,&timeb);
}


}
else
aux++;



}

if (timeb>timea)
{

{
if(((timeb-timea)!=2) || (timeb<15))
{

if((timeb==15) && ((timeb-timea)>=2))
{
aux++;
}
else
{
aux=0;
printf (´\nINVALIDO\n´);
printf (´PONTOS DO TIME A \n´);
scanf (´¬d´,&timea);
printf (´PONTOS DO TIME B \n´);
scanf (´¬d´,&timeb);
}


}
else
aux++;


}




}
}

if(timea>timeb)
vita++;
if(timeb>timea)
vitb++;

}

}

if (vita>vitb)
printf(´ \n TIME A VENCE!´);
else
printf(´ \n TIME B VENCE!´);

getch();
}


Predacon

Predacon

Responder

Que tal ter acesso a um e-book gratuito que vai te ajudar muito nesse momento decisivo?

Ver ebook

Recomendado pra quem ainda não iniciou o estudos.

Eu quero
Ver ebook

Recomendado para quem está passando por dificuldades nessa etapa inicial

Eu quero

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar