Reputation: 13
Just started using C and I'm getting 1 error on my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
//declare variables
double speed = 1.4, hours, totalYards;
//prompt user to enter amount of hours
printf("Enter the amount of hours: ");
scanf("%lf", &hours);
//calculate amount of yards taken
totalYards = speed * hours;
//display result to user
printf("The total amount of yards is %.2f", &totalYards);
return 0;
}
and the error is
warning: format '%f' expects argument of type 'double', but argument 2 has type 'double *' [-Wformat]|
on the last printf.
Upvotes: 0
Views: 8659
Reputation: 145839
Change
printf("The total amount of yards is %.2f", &totalYards);
to
printf("The total amount of yards is %.2f", totalYards);
You were passing a pointer object (type double *
) but f
requires you to pass a value of type double
.
Upvotes: 4