Write a program that prompts a user to input the city name, distance, and travel time for three destination citites. Your program will use 2 new typedef structs to store the information, then find and output the tour with the shortest distance. Your first new typedef should: • be named timeType, with a struct named time Type_struct contain 3 data members: o hours, minutes, and seconds as integer values Your second new typef should: • be named tourType, with a struct named tour Type_struct contain 3 data members: o a 50 character city name O an integer distance O a travel time as data type time Type Your program will need the following 2 functions: ● a function that prompts a user to input the values for the data members of a tourType struct and returns the tourType struct to the calling function • a void function that takes a tourType parameter and prints the data in the struct Within your main function you will need to: ● create a 3 element tourType array ● use your value-returning function to prompt for and read data into the array • loop through the array to find the tour with the shortest distance ● use your void function to print the tour with the shortest distance NOTES: Be sure to include your function prototypes before your main function, and your function definitions after your main function. Sample output (sample input shown with underline): Enter tour data for 3 cities: Enter a city name: Chicago Enter an integer distance: 300 Enter travel time as HH:MM:SS: 06:00:01 Enter a city name: Pittsburgh Enter an integer distance: 600 Enter travel time as HH:MM:SS: 10:30:00 Enter a city name: Miami Enter an integer distance: 500 Enter travel time as HH:MM:SS: 08:00:00 Shortest Tour City name: Chicago Distance: 300 Travel time: 06:00:01
Here is my code:
#include<stdio.h>
struct timeType_struct {
int hr;
int min;
int sec;
};
typedef struct timeType_struct timeType;
struct tourType {
char city[50];
int distance;
timeType time;
};
typedef struct tourType tourType;
void printTour(tourType *);
tourType getData();
tourType tours[3];
int main() {
int i=0, min;
printf("Enter tour data for 3 cities...\n");
for (i = 0;i < 3;i++) {
tours[i] = getData();
}
min = tours[0].city;
for (i = 0;i < 3;i++) {
if (tours[i].distance < min)
min = tours[i].distance;
}
printf("\n");
for (i = 0;i < 3; i++) {
if (tours[i].distance == min) {
printTour(&tours[i]);
}
}
getchar();
return 0;
}
void printTour(tourType* x) {
printf("Shortest Tour\n---------------\n");
printf("City name: %s\n", (*x).city);
printf("Distance: %d\n", (*x).distance);
printf("Travel time: %02d:%02d:%02d", (*x).time.hr, (*x).time.min, (*x).time.sec);
}
tourType getData() {
tourType x;
char a[5], b[5], c[5]; //Will be used for time input
printf("Enter a city name: ");
scanf("%s", &x.city);
printf("Enter an integer distance: ");
scanf("%d", &x.distance);
printf("Enter travel time as HH:MM:SS ");
scanf("%[^:]:%[^:]:%[^\n]", a, b, c);
return x;
}
Whenever I try to run it i get these warnings (see screenshot)
I attached the picture of what the output is suppose to be to.

![user@mimir: ~/cpsc1010_s21/chapterproject_71 > gcc -Wall C7.1.c
C7.1.c: In function 'main':
C7.1.c:39:5: warning: assignment to ʼint' from 'char *' makes integer fro
m pointer without a cast [-Wint-conversion]
min =
tours[0].city;
A
C7.1.c: In function 'getData':
C7.1.c:63:9: warning: format '%s' expects argument of type 'char *', but
argument 2 has type ʼchar (*)[50]' [-Wformat=]
scanf("%s", &x.city);
user@mimir: ~/cpsc1010_s21/chapterproject_71 >](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe330c000-35a4-4408-bbb0-b12f934c95a4%2Fd1ad0471-b79c-49ec-8e2e-4e6384e8fafa%2Fn7td2w5_processed.png&w=3840&q=75)

Step by step
Solved in 5 steps with 4 images









