0
Good evening guys, I’m with a code that shows me wrong values, in my view, my logic is correct but when I request result what is shown has nothing to do with the final objective of the code.
I have an activity that requests the name of the customer and the amount of dvd’s rented by him, based on the amount entered by the user the program must calculate how many rentals he would have free. For every 10 Dvds rented by him, he would have 1 free rental, that is, 54 paid rentals, 5 free rentals. The solution I found was as follows:
aux = valor / 10; //54 / 10 = 5,4
aux = aux % 10; //5,4 % 10 = 5
But always receive as return values above or below expected. Here’s my code below.
include
include
include
int main(void)
{
setlocale(LC_ALL, "");
int i, varaux;
int vetorB[10];
char vetorA[50][8];
for(i = 0; i < 5; i++)
{
printf("Insira o nome completo do cliente, número [%i]: ", i+1);
scanf("%s", &vetorA[i]);
}
printf("\n");
for(i = 0; i < 5; i++)
{
printf("Insira a total de DVD's locados pelo cliente: %s ", vetorA[i]);
scanf("%f", &vetorB[i]);
}
printf("\n");
for(i = 0; i < 5; i++)
{
if(vetorB[i] > 10)
{
varaux = vetorB[i] / 10;
varaux = varaux % 10;
printf("O cliente %s possui um total de %i locações.\n", vetorA[i], varaux);
}
else
{
printf("O cliente não possui locações o suficiente. TOTAL: %i\n", vetorB[i]);
}
}
}