M
marsiputkin
Доброго всем времени суток)..Моя проблема заключается в том, что в субботу надо сдавать задачу, а код, который внизу, программа не принимает.
Программа должна работать по принципу:
Введите время прибытия поездa A:
12:00
Введите время отправления поезда A:
12:30
Введите время прибытия поезда B:
12:10
Введите время отправления поезда B:
12:20
Введите время прибытия поезда C:
12:40
Введите время отправления поезда C:
13:00
С поезда А можно перейти в поезда B и C.
С поезда В можно перейти в поезда А и C.
С поезда С нельзя переступить.
Введите время отправления поезда:
12:65
Неправильный ввод.
Введите время отправления поезда:
12: ABC
Неправильный ввод.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char **argv) {
int a1_h, a1_m, a2_h, a2_m; /*
* Arrival time (hours, minutes)
* And departure time (hours, minutes)
* Train A.
*/
int b1_h, b1_m, b2_h, b2_m; /* Similarly for train B.*/
int c1_h, c1_m, c2_h, c2_m; /* Similarly for train C. */
time_t a1_u, a2_u; /*
* Time of arrival and departure of the train A
* In UNIX-format
* (Number of seconds since 1970-01-01 00:00:00 UTC)
*/
time_t b1_u, b2_u; /* Similarly for train B. */
time_t c1_u, c2_u; /* Similarly for train C. */
struct tm *newtime;
time_t change = 5 * 60; /*
* Time required for transplant
* from train to train, in seconds.
*/
time_t wait = 30 * 60; /*
* Stand by time
* the next train, in seconds.
*/
int transfer; /* Is it possible to change? */
time_t t;
t = time(NULL);
newtime = localtime(&t);
newtime->tm_sec = 0;
printf("\n");
printf("Enter the arrival and departure of trains" \
" in hh: mm.\n");
printf(" arrival of the train A: ");
scanf("%d:%d", &a1_h, &a1_m);
newtime->tm_hour = a1_h;
newtime->tm_min = a1_m;
a1_u = mktime(newtime);
do {
printf(" departure of the train A: ");
scanf("%d:%d", &a2_h, &a2_m);
newtime->tm_hour = a2_h;
newtime->tm_min = a2_m;
a2_u = mktime(newtime);
} while (a1_u >= a2_u);
printf(" arrival of the train B: ");
scanf("%d:%d", &b1_h, &b1_m);
newtime->tm_hour = b1_h;
newtime->tm_min = b1_m;
b1_u = mktime(newtime);
do {
printf(" departure of the train B: ");
scanf("%d:%d", &b2_h, &b2_m);
newtime->tm_hour = b2_h;
newtime->tm_min = b2_m;
b2_u = mktime(newtime);
} while (b1_u >= b2_u);
printf(" arrival of the train C: ");
scanf("%d:%d", &c1_h, &c1_m);
newtime->tm_hour = c1_h;
newtime->tm_min = c1_m;
c1_u = mktime(newtime);
do {
printf(" departure of the train C: ");
scanf("%d:%d", &c2_h, &c2_m);
newtime->tm_hour = c2_h;
newtime->tm_min = c2_m;
c2_u = mktime(newtime);
} while (c1_u >= c2_u);
printf("\n");
/* If the train arrives at A */
transfer = 0;
if (b2_u - a1_u >= change && b2_u - a1_u <= wait) {
printf("With the A train can be a train B.\n");
++transfer;
}
if (c2_u - a1_u >= change && c2_u - a1_u <= wait) {
printf("With the A train can be a train C.\n");
++transfer;
}
if (transfer == 0) {
printf("From train A transfer is not possible.\n");
}
/* If the train arrives at B */
transfer = 0;
if (a2_u - b1_u >= change && a2_u - b1_u <= wait) {
printf("With the B train can be a train A.\n");
++transfer;
}
if (c2_u - b1_u >= change && c2_u - b1_u <= wait) {
printf("With the B train can be a train C.\n");
++transfer;
}
if (transfer == 0) {
printf("From train B transfer is not possible.\n");
}
/* If the train arrives at C */
transfer = 0;
if (a2_u - c1_u >= change && a2_u - c1_u <= wait) {
printf("With the C train can be a train A.\n");
++transfer;
}
if (b2_u - c1_u >= change && b2_u - c1_u <= wait) {
printf("With the C train can be a train B.\n");
++transfer;
}
if (transfer == 0) {
printf("From train C transfer is not possible.\n");
}
printf("\n");
return EXIT_SUCCESS;
}
<pre><code class="cpp"></code></pre>
Заранее большое спасибо тем, кто мне поможет
Программа должна работать по принципу:
Введите время прибытия поездa A:
12:00
Введите время отправления поезда A:
12:30
Введите время прибытия поезда B:
12:10
Введите время отправления поезда B:
12:20
Введите время прибытия поезда C:
12:40
Введите время отправления поезда C:
13:00
С поезда А можно перейти в поезда B и C.
С поезда В можно перейти в поезда А и C.
С поезда С нельзя переступить.
Введите время отправления поезда:
12:65
Неправильный ввод.
Введите время отправления поезда:
12: ABC
Неправильный ввод.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char **argv) {
int a1_h, a1_m, a2_h, a2_m; /*
* Arrival time (hours, minutes)
* And departure time (hours, minutes)
* Train A.
*/
int b1_h, b1_m, b2_h, b2_m; /* Similarly for train B.*/
int c1_h, c1_m, c2_h, c2_m; /* Similarly for train C. */
time_t a1_u, a2_u; /*
* Time of arrival and departure of the train A
* In UNIX-format
* (Number of seconds since 1970-01-01 00:00:00 UTC)
*/
time_t b1_u, b2_u; /* Similarly for train B. */
time_t c1_u, c2_u; /* Similarly for train C. */
struct tm *newtime;
time_t change = 5 * 60; /*
* Time required for transplant
* from train to train, in seconds.
*/
time_t wait = 30 * 60; /*
* Stand by time
* the next train, in seconds.
*/
int transfer; /* Is it possible to change? */
time_t t;
t = time(NULL);
newtime = localtime(&t);
newtime->tm_sec = 0;
printf("\n");
printf("Enter the arrival and departure of trains" \
" in hh: mm.\n");
printf(" arrival of the train A: ");
scanf("%d:%d", &a1_h, &a1_m);
newtime->tm_hour = a1_h;
newtime->tm_min = a1_m;
a1_u = mktime(newtime);
do {
printf(" departure of the train A: ");
scanf("%d:%d", &a2_h, &a2_m);
newtime->tm_hour = a2_h;
newtime->tm_min = a2_m;
a2_u = mktime(newtime);
} while (a1_u >= a2_u);
printf(" arrival of the train B: ");
scanf("%d:%d", &b1_h, &b1_m);
newtime->tm_hour = b1_h;
newtime->tm_min = b1_m;
b1_u = mktime(newtime);
do {
printf(" departure of the train B: ");
scanf("%d:%d", &b2_h, &b2_m);
newtime->tm_hour = b2_h;
newtime->tm_min = b2_m;
b2_u = mktime(newtime);
} while (b1_u >= b2_u);
printf(" arrival of the train C: ");
scanf("%d:%d", &c1_h, &c1_m);
newtime->tm_hour = c1_h;
newtime->tm_min = c1_m;
c1_u = mktime(newtime);
do {
printf(" departure of the train C: ");
scanf("%d:%d", &c2_h, &c2_m);
newtime->tm_hour = c2_h;
newtime->tm_min = c2_m;
c2_u = mktime(newtime);
} while (c1_u >= c2_u);
printf("\n");
/* If the train arrives at A */
transfer = 0;
if (b2_u - a1_u >= change && b2_u - a1_u <= wait) {
printf("With the A train can be a train B.\n");
++transfer;
}
if (c2_u - a1_u >= change && c2_u - a1_u <= wait) {
printf("With the A train can be a train C.\n");
++transfer;
}
if (transfer == 0) {
printf("From train A transfer is not possible.\n");
}
/* If the train arrives at B */
transfer = 0;
if (a2_u - b1_u >= change && a2_u - b1_u <= wait) {
printf("With the B train can be a train A.\n");
++transfer;
}
if (c2_u - b1_u >= change && c2_u - b1_u <= wait) {
printf("With the B train can be a train C.\n");
++transfer;
}
if (transfer == 0) {
printf("From train B transfer is not possible.\n");
}
/* If the train arrives at C */
transfer = 0;
if (a2_u - c1_u >= change && a2_u - c1_u <= wait) {
printf("With the C train can be a train A.\n");
++transfer;
}
if (b2_u - c1_u >= change && b2_u - c1_u <= wait) {
printf("With the C train can be a train B.\n");
++transfer;
}
if (transfer == 0) {
printf("From train C transfer is not possible.\n");
}
printf("\n");
return EXIT_SUCCESS;
}
<pre><code class="cpp"></code></pre>
Заранее большое спасибо тем, кто мне поможет