0
Hello, I have an activity to be done that consists of receiving values and only stop receiving them when typing -1, then the program should display the 3 highest values typed as if it were a ranking of first, second and third place. I broke my head a lot and managed to write the program, I receive all values, but at the time of printing it always shows -1 in the 3 printing houses(-1 is the command that for the loop to receive the values)I believe it is a very slight mistake that is compromising the program.Thank you for understanding. The activity describes that vectors should not be used.Before asking the name of the variables plu, slu and tlu are to represent first second and third place.
#include <stdio.h>
#include <stdlib.h>
main()
{
int pon = 0, plu, slu, tlu;
while (pon != -1)
{
printf("Insira a pontuacao dos jogadores\n");
scanf("%d", &pon);
plu = pon ;
slu = pon ;
tlu = pon ;
}
if (plu >= slu)
if (slu >= tlu)
printf(" 1 Lugar %d\n 2 Lugar %d\n 3 Lugar %d\n",plu,slu,tlu);
else
if (plu >= tlu)
printf(" 1 Lugar %d\n 3 Lugar %d\n 2 Lugar %d\n", plu, tlu, slu);
else
printf(" 3 Lugar %d\n 1 Lugar %d\n 2 Lugar %d\n", tlu, plu, slu);
else
if (slu >= tlu)
if (plu >= tlu)
printf(" 2 Lugar %d\n 1 Lugar %d\n 3 Lugar %d\n", slu, plu, tlu);
else
printf(" 2 Lugar %d\n 3 Lugar %d\n 1 Lugar %d\n", slu, tlu, plu);
else
printf(" 3 Lugar %d\n 2 Lugar %d\n 1 Lugar %d\n", tlu, slu, plu);
return 0;
}
It would be good to even your code, it would make it very easy to read. From what I see, your loop does nothing, when the user type
-1
and stop, the value assigned to the variablesplu
,slu
,tlu
will always be-1
why was the user’s last entry– Costamilam
The way you did the result will be -1, -1 and -1. When reading a new score you have to check if it fits into one of the 3 maximum scores and scroll below them by placing it in its proper place. Do not need to do this bunch of tests at the end, just print the 3 values.
– anonimo
regarding:
main()
there are only two valid signatures for themain ()
They are:int main (void)
andint main (inc argc, char * argv [])
– user3629249