1

このコードが機能しないのはなぜですか?

基本的な考え方:

各車両には 4 人が乗車できます。各列車の最初の車両の長さは 10 フィートで、後続の各車両の長さは 8 フィートです。列車は全線路長の 25% しか占有できません。
目標は、最大線路長と最大列車長のユーザー入力を使用して、線路に配置できる最大人数を出力することです。

//Roller Coaster Capacity
//Justin Castillo, Section 1, COP 3223, 2/9/2013
//This program calculates the maximum number of people that can be on the
//track at one time.  

int main(void) {

    int max_people_train;
    int num_cars_train;
    int total_num_trains;
    int max_length_track;
    int max_length_train;
    int max_people_track;
    int prev_max_people_track;
    int prev_total_num_trains, i;

    printf("Please enter the track length:\n");
    scanf("%d", &max_length_track);

    printf("Please enter the max length of the train:\n");
    scanf("%d", &max_length_train);

    for (i=10; i<=max_length_train; i+8) {
        num_cars_train = ((i-10)/8 +1);
        max_people_train = (num_cars_train)*4;
        total_num_trains = max_length_track/i;
        max_people_track = total_num_trains*max_people_train;

        prev_max_people_track = prev_total_num_trains * max_people_train;
        prev_total_num_trains = max_length_track/(i-8);

        if (prev_max_people_track > max_people_track)
            max_people_track = prev_max_people_track;
    }



    printf("Your ride can have at most %d people on the track,\n", max_people_track);
    printf("This can be achieved with trains of %d cars.\n", num_cars_train);


    system("pause");
    return 0;
}
4

1 に答える 1

1

私はそれがこれと関係があると推測しています:

for (i=10; i<=max_length_train; i+8) {
//  ============================^^^ WTF ?

試す:

for (i=10; i<=max_length_train; i+=8) {
于 2013-02-11T03:56:39.937 に答える