4
I am trying to create a game in which the user must determine an interval and guess a random number that is generated within this range. When the user inserts a number to guess, the program must reply with one of the following messages:
The code so far is like this:
Being "Resp" the generated random number, "Tent" the attempts, "num" the number the user inserts, and "n" the range the user determines in Random().
int random();
void dicas(int num, int resp, int tent);
int main()
{
int continuar=1,
resp,
tent,
num,
n;
do{
system("cls || clear");
resp = random();
printf("Comecou! Tente adivinhar o numero!\n\n");
tent = 0;
do{
tent++;
printf("Tentativa %d: ", tent);
scanf("%d", &num);
dicas(num,resp,tent);
}while( num != resp);
printf("Digite 0 para sair, ou qualquer outro numero para continuar: ");
scanf("%d", &continuar);
}while(continuar);
}
int random()
{
int n;
printf("Insira o valor maximo que pode ser sorteado: ");
scanf("%d", &n);
printf("Sorteando numero entre 1 e %d...\n",n);
srand((unsigned)time(NULL));
return (1+rand()% n);
}
void dicas(int num, int resp, int tent)
{
if(num>resp)
printf("O numero sorteado e menor que %d\n\n", num);
else if (num<resp)
printf("O numero sorteado e maior que %d\n\n", num);
else
printf("Parabens! Voce acertou o numero em %d tentativas!\n\n", tent);
}
My problem is in the tips, the current ones don’t correspond to what I need to do, but I don’t know which operations to insert so it shows the answers according to the table.
Note that the tag [tag:codeblocks] has this at the end of the description: "If the question is not about Codeblocks, do not use this tag, even if you are using Codeblocks in your project."
– Bacco
This smells like college work. (=
– William Monteiro
Yes. The first half of the job is in that question :) :) :). Felipe, what exactly are you in doubt about? In calculating the percentage?
– Anthony Accioly
Yes, it’s in the application. I’ve tried 3 different operations and they didn’t work. And yes, the work is college, it’s a matter completion project. My question is inside the "void tips(int num, int Resp, int Tent)", I need to insert the answers of the table there, with the operations, etc.
– Felipe Nesello
Don’t put the
srand()
inside a function that will be called several times: put it inside the functionmain()
.– pmg