Reputation: 11
This was my school assignment and the feedback from the professor says violates the rule of type-mismatch and also avoid trailing spaces. I couldn't still pinpoint the exact problem.
#include<stdio.h>
#define SECS_PER_HOUR 3600 //1 hour = 60mins * 60 secs = 3600 secs
#define METERS_PER_MILE 1600
int main()
{
double distance, time, speedmph, speedmps;
scanf("%lf", &distance);
scanf("%lf", &time);
speedmph = distance / time;
speedmps = (speedmph * METERS_PER_MILE) / SECS_PER_HOUR;
printf("\nThe speed is %.2f miles per hour. \n", speedmph);
printf("The speed is %.2f meters per second. \n\n", speedmps);
main();
}
Upvotes: 0
Views: 307
Reputation: 12653
Most probably your code should look like this:
#include<stdio.h>
#define SECS_PER_HOUR 3600 // 1 hour = 60mins * 60 secs = 3600 secs
#define METERS_PER_MILE 1600
int main(void)
{
for (;;)
{
double distance;
double time;
double speedmph;
double speedmps;
scanf("%lf", &distance);
scanf("%lf", &time);
speedmph = distance / time;
speedmps = (speedmph * METERS_PER_MILE) / SECS_PER_HOUR;
printf("\nThe speed is %.2lf miles per hour.\n", speedmph);
printf("The speed is %.2lf meters per second.\n\n", speedmps);
}
}
Changes are:
%.2f
into %.2lf
to match the double
. However, as @user3386109 wrote, for printf()
its the same. If there were some float
it would be casted to a double
.\n
.Upvotes: 2