-1

Помогите, не работает, нужно найти худшее среднее значение из трёх предметов

#include <iostream>

#define STOP "*"

using namespace std;

struct STUDENT
{
    char name1;
    int mark1;
    int mark2;
    int mark3;
    double ser;
};


void ArrayIn(STUDENT* s, int num, double *mass) {      // Ввод
    for (int i = 0; i < num; i++) {
        cout << "Enter name: " << endl;
        cin >> s[i].name1;
        cout << "Enter mark1= ";
        cin >> s[i].mark1;
        cout << "Enter mark2= ";
        cin >> s[i].mark2;
        cout << "Enter mark3= ";
        cin >> s[i].mark3;
    } 

}

void ArrayAvarage(STUDENT* s, int num) { //Нахождение среднего значения
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < num; j++) {
            s[i].ser += s[j].mark1;
        }
        cout << "SER= " << s[i].ser << endl;
    }
}

void ArrayOut(STUDENT* s, int num) {              //Нахождение худшего и вывод его на экран
    double bad = s[0].ser;
    for (int i = 1; i <= 3; i++) {
        if (bad > s[i].ser) {
            bad = s[i].ser;
        }
    }
    if (bad == s[1].ser) {
        cout << "Math the worst: " << bad << endl;
    }
    else
        if (bad == s[2].ser) {
            cout << "History the worst: " << bad << endl;
        }
        else
        {
            cout << "Programmic the worst: " << bad << endl;
        }
}


int main() {
    system("color 4");
    int num;
    cout << "Enter num= ";
    cin >> num;
    double *mass = new double[num];
    static STUDENT s[90];
    ArrayIn(s, num, mass);
    ArrayAvarage(s, num);
    ArrayOut(s, num);
    system("pause");
}


2
  • Опишите в тексте вопроса, что не работает, как проявляется неработоспособность и каков ожидаемый результат. От куска кода без пояснений толку не очень много
    – andreymal
    8 апр 2020 в 18:31
  • Среднее значение всегда одинаковое, будто стракт только один
    – ツFetix
    8 апр 2020 в 18:36

1 ответ 1

1

Много всяких правок: 1) среднее по предметам не должно быть членом структуры STUDENT, а внесено в отдельную структуру. 2) всегда забываешь в формальных параметрах указывать ключевое слово struct (тогда уж typedef сделай, чтобы постоянно это не писать). 4) Имя студента - строка, если string не хочешь использовать, то тогда сишная строка это массив char-ов. Сделал, так как скучно дома) У тебя вроде и код свой написан, так что можно помочь. Надеюсь правильно понял выражение "худшее среднее значение из 3-х предметов"

#include <iostream>
#include <stdlib.h>
using namespace std;

struct COURSES
{
    double math_ser;
    double history_ser;
    double prog_ser;
};

struct STUDENT
{
    char name[50];
    int mark_math;
    int mark_history;
    int mark_prog;
};

// Ввод информации об успеваемости
void ArrayIn(struct STUDENT* s, int num) {      
    for (int i = 0; i < num; i++) {
        cout << "Enter student name: " << endl;
        cin >> s[i].name;
        cout << "Enter mark (math) = ";
        cin >> s[i].mark_math;
        cout << "Enter mark (history) = ";
        cin >> s[i].mark_history;
        cout << "Enter mark (prog) = ";
        cin >> s[i].mark_prog;
    } 
}

//Нахождение средих значений по курсам
void ArrayAvarage(struct STUDENT* s, struct COURSES *c, int num) { 
    for(int i = 0; i < num; i++) {
        c->math_ser += s[i].mark_math;
        c->history_ser += s[i].mark_history;
        c->prog_ser += s[i].mark_prog;
    }
    c->math_ser /= (double)num;
    c->history_ser /= (double)num;
    c->prog_ser /= (double)num;
}

//Нахождение худшего и вывод его на экран
void ArrayOut(struct COURSES* c) {              
    if ((c->math_ser <= c->history_ser) && (c->math_ser <= c->prog_ser)) {
        cout << "Math the worst: " << c->math_ser << endl;
    }
    else if ((c->history_ser <= c->math_ser) && (c->history_ser <= c->prog_ser)) {
        cout << "History the worst: " << c->math_ser << endl;
    }
    else if ((c->prog_ser <= c->math_ser) && (c->prog_ser <= c->history_ser)) {
        cout << "Prog the worst: " << c->math_ser << endl;
    }
}

int main() {
    system("color 4");
    int num;
    cout << "Enter num of students: ";
    cin >> num;
    static struct COURSES c;
    static struct STUDENT s[90];
    ArrayIn(s, num);
    ArrayAvarage(s, &c, num);
    ArrayOut(&c);
    system("pause");
    return 0;
}
1
  • Спасибо тебе большое
    – ツFetix
    9 апр 2020 в 16:10

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.