Reputation: 1
The code works fine, it's running and everything;
printf("\nEnter number of hours ");
scanf("%f", &hours);
{
if (hours>=5) {
calc_charge=minimum_fee;
bill = hours * minimum_fee;
printf("%i", &bill);
}
else
if(hours>=8) {
bill=hours*mini_fee;
printf("%i", &bill);
}
else
if (hours <= 24) {
bill = hours*maximum_fee;
printf("%i", &bill);
}
while (hours >= 4) {
bill = hours*minimum_fee;
printf("%i", &bill);
}
But the output is
34525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160134525160
I can't seem to find anything wrong, the code is just not doing the calculations. Why not?
Upvotes: 0
Views: 109
Reputation: 28251
There is an infinite loop in your code:
while (hours >= 4) {
bill = hours*minimum_fee;
printf("%i", &bill);
}
Maybe you want to print only once:
bill = hours*minimum_fee;
printf("%i", &bill);
Or maybe you wanted to write if
instead of while
? (just a guess, not a suggestion)
Upvotes: 1
Reputation: 9385
Additionally to removing the &
as suggested by Armin, it might also help to add newlines \n
s or at least spaces to your printfs, e.g.:
printf("%i\n", bill);
Otherwise your numbers are printed right next to each other.
Upvotes: 2
Reputation:
Remove &
at all of your printfs. You want to print the value of the variable not its address.
Upvotes: 12