My program is supposed to take num (number of clients that'll have a discount calculated for), than it goes into 'for' and starts the loop of asking the clients name (char name) and how much he spent on the store (float value), and calculates the discount. The problem is, it is printing trash values before printing the right ones.
#include <stdio.h>
int main()
{
int num = 0, i = 0;
char name = '\0';
float value = 0.0;
scanf("%d", &num);
for (i = 0; i < num; i++)
{
scanf("%c %f", &name, &value);
if (value < 500)
{
value = value / 10;
printf("\nClient %c has a %.3f$ bonus!\n", name, value);
}
else
{
value = value / 100 * 15;
printf("\nClient %c has a %.3f$ bonus!\n", name, value);
}
}
return 0;
}
If I insert name and value, it'll first print the initial values of my variables first. What is going on here? How can I fix it?