Good evening, I have a code that shows me wrong values, in my opinion, my logic is correct, but when I request results, what is shown has nothing to do with the ultimate goal 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 leases he would have for free. Every 10 Dvd's rented by him, he would have 1 free rental, that is, 54 rentals paid, 5 free rentals. The solution found by me was as follows:
aux = valor / 10; //54 / 10 = 5,4
aux = aux % 10; //5,4 % 10 = 5
But I always receive returns as above or below expectations. 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]);
}
}
}