#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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps