I was wondering how to get rid of the 1.#J output that appears when it is run. I know it is related to the float mpg variable after the trip selection part. I am just beginning to use C, so any help is greatly appreciated. Also, the program is not yet finished.
#include <stdio.h>
#define MAX_LEN 80
float mpg, distance;
int main ( )
{
int name[MAX_LEN];
printf("Hello! Can you please enter your name: ");
scanf("%s", name);
printf("Okay, %s, Let's begin!\n", name);
char answer;
printf("%s, do you own a car? (Y or N):");
scanf(" %c", &answer);
while (answer == 'y' || answer == 'Y')
{
printf("Great, welcome to the road trip calculator.\n");
printf("\n");
printf("First we will need to know somethings about your car.\n");
float gal_to_fill;
printf("About how many gallons of gas does it take to fill it up: ");
scanf("%f", &gal_to_fill);
printf("%.2f\n",gal_to_fill);
float mpg;
printf("About how many miles can you drive per gallon: ");
scanf("%f", &mpg);
printf("%.2f\n",mpg);
printf("Okay, now let's pick a location to travel to.\n");
printf("We are going to start at ________\n");
printf("Please pick a final destination:\n");
printf("1. Boston, MA\n");
printf("2. New York, NY\n");
printf("3. Miami, FL\n");
printf("4. Chicago, IL\n");
printf("5. San Francisco, CA\n");
break;
}
int trip;
printf("Enter the number of your choice: ");
scanf("%d", &trip);
while(trip == 1,2,3,4,5)
{
if (trip == 1)
{
float mpg;
float distance = 141.9;
printf("This trip is 141.9 miles\n");
float gal_used;
gal_used = distance/mpg;
printf("%.2f\n",gal_used);
break;
}
else if (trip == 2)
{
float distance = 343.6;
printf("This trip is 343.6 miles\n");
float gal_used;
gal_used = distance/mpg;
printf("%.2f\n", gal_used);
break;
}
else if (trip == 3)
{
float distance = 1623.3;
printf("This trip is 1623.3 miles\n");
float gal_used;
gal_used = distance/mpg;
printf("%.2f\n", gal_used);
break;
}
else if (trip == 4)
{
float distance = 1112.8;
printf("This trip is 1112.8 miles\n");
float gal_used;
gal_used = distance/mpg;
printf("%.2f\n", gal_used);
break;
}
else if (trip == 5)
{
float distance = 3227.2;
printf("This trip is 3227.2 miles\n");
float gal_used;
gal_used = distance/mpg;
printf("%.2f\n", gal_used);
break;
}
}
return 0;
}