D
D
Danya Kozlovskiy2020-12-27 22:16:21
C++ / C#
Danya Kozlovskiy, 2020-12-27 22:16:21

Does the program skip input or break?

when you enter in students[i].fio (where the comment is), the program breaks, or skips the input altogether. Tried with both char and string and cin and getline. Guide the young mind, help the martyr.

#include <iostream>
#include <windows.h>
#include <string>
using namespace std;

int main()
{
  setlocale(LC_ALL, "ru_RU.UTF-8");
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);
  struct Student
  {
    string fio;
    int group;
    int yspeh[5];
    double sredn;
  };
  int n;
  cout << " Введите количество студентов: ";
  cin >> n;
  Student *students = new Student[n];
  for (int i = 0; i < n; i++)
  {
    cout << "Введите ФИО: ";
    cin >> students[i].fio; // тут ломается программа!!!!!!!!!!!!!!!!!!11
    cout << "Введите групу: ";
    cin >> students[i].group;
    cout << "Введите оценки: ";
    for (int j = 0; j < 5; j++)
    {
      cout << j + 1 << " : ";
      cin >> students[i].yspeh[j];
    }
  }
  double sredn = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < 5; j++)
    {
      sredn += students[i].yspeh[j];
    }
    students[i].sredn = sredn / 5.0;
    sredn = 0;
  }
  int temp;
  for (int i = 0; i < n; i++)
  {
    for (int j = i; j < n; j++)
    {
      if (students[i].sredn > students[j].sredn)
        swap(students[i], students[j]);
    }
  }
  for (int i = 0; i < n; i++)

  {
    cout << "ФИО\t" << students[i].fio << "\n"; 
    cout << "Номер группы\t" << students[i].group << "\n";
    cout << "Оценки\t";
    for (int j = 0; j < 5; j++)
    {
      cout << students[i].yspeh[j] << "\t";
    }
    cout << "\n";
    cout << "Среднее знач:\t" << students[i].sredn << "\n";
  }
  string vopros;
  cout << "Вывести студентов с оценкой 4 или 5?" << endl;
  cin >> vopros;
  if (vopros != "нет")
  {
    int check;
    if (vopros == "4")
    {
      for (int i = 0; i < n; i++)
      {
        check = 0;
        for (int j = 0; j < 5; j++)
        {
          if (students[i].yspeh[j] != 4)
            check = 1;
          break;
        }

        if (check == 0)
        {
          cout << "ФИО\t" << students[i].fio << "\n";
          cout << "Номер группы\t" << students[i].group << "\n";
          cout << "Оценки\t";
          for (int j = 0; j < 5; j++)
          {
            cout << students[i].yspeh[j] << "\t";
          }
          cout << "\n";
          cout << "Среднее знач:\t" << students[i].sredn << "\n";
        }
      }
    }
    else if (vopros == "5")
    {
      for (int i = 0; i < n; i++)
      {
        check = 0;
        for (int j = 0; j < 5; j++)
        {
          if (students[i].yspeh[j] != 5)
            check = 1;
          break;
        }

        if (check == 0)
        {
          cout << "ФИО\t" << students[i].fio << "\n";
          cout << "Номер группы\t" << students[i].group << "\n";
          cout << "Оценки\t";
          for (int j = 0; j < 5; j++)
          {
            cout << students[i].yspeh[j] << "\t";
          }
          cout << "\n";
          cout << "Среднее знач:\t" << students[i].sredn << "\n";
        }
      }
    }
  }
  else
  {
    cout << "До свидания";
  }
  system("PAUSE");
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question