#include 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;
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;
but i need it to what is in the picture in C
![DESCRIPTION
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 timeType_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 tourType_struct
• contain 3 data members:
o a 50 character city name
o an integer distance
a travel time as data type timeType
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe330c000-35a4-4408-bbb0-b12f934c95a4%2F91356e4e-54e6-41f0-bbed-48792d59eaff%2F8gbdsyb_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)