Any errors in the code, the search function simply displays the last person on the list, but should display the blond with the maximum height. Where are the mistakes? Thanks in advance for any help.

#include <conio.h> #include <iomanip> #include <iostream> #include <string> using namespace std; struct student { string fam, cvet; float rost, ves; }; short fMenu (); void fwriteinfile (char *file_name, student *pstud); void fvvod (student *pstud); void fpoisk(student *pstud); void freadfromfile (char *file_name); int n = 6; int main() { short choise; int count=0; char *fName = "D:\\student3.txt"; student *stud = new student[n]; do { cout<< "Studentov v spiske - "<< count << "/" << n <<endl; choise = fMenu(); switch (choise) { case 1: system("cls"); fwriteinfile(fName, stud); count++; _getch(); system("cls"); break; case 2: system("cls"); freadfromfile(fName); _getch(); system("cls"); break; case 3: system("cls"); fpoisk(stud); _getch(); system("cls"); break; case 0: cout << "Do svidaniya!!!" << endl; system ("pause"); break; default: cout << "Oshibka vvoda!!!" << endl; cout << "\n\nPress Enter..." << endl; _getch(); system("cls"); break; } } while(choise); cout << endl; return 0; } short fMenu () { short ch; cout << "|--------------------- MENU ----------------------------------------------|\n"; cout << "| [1] Vvod |" << endl; cout << "| [2] Vivod |" << endl; cout << "| [3] Poisk |" << endl; cout << "| [0] Vihod |" << endl; cout << "|-------------------------------------------------------------------------|\n"; cout << "Vash vibor: "; cin >> ch; return ch; } void fvvod (student *pstud) { cin.ignore(); cout <<"Vvedite informaciyu o studentah"<<endl; cout << "Familiya: "; getline(cin, pstud->fam); cout << "Rost: "; cin >> pstud->rost; cout << "Ves: "; cin >> pstud->ves; cout << "Cvet volos: "; cin >> pstud->cvet; cout<<endl; } void fwriteinfile (char *file_name, student *pstud) { fvvod(pstud); FILE *pfile = fopen(file_name,"ab"); cout<<" ЦДДДТДДДДДДДДДДДДТДДДДДДТДДДДДТДДДДДДДДДДДДДДД·"<<endl; cout<<" є N є Familiya є Rost є Ves є Cvet volos є"<<endl; cout<<" ЗДДДЧДДДДДДДДДДДДЧДДДДДДЧДДДДДЧДДДДДДДДДДДДДДД¶"<<endl; cout<<" є " " є"<<setw(10)<<pstud->fam<<" є"<<setw(7)<<fixed<<setprecision(2)<< pstud->rost<<" є"<<setw(7)<<pstud->ves; cout<<" є"<<setw(15)<<pstud->cvet<<" є"<<endl; cout<<" УДДДРДДДДДДДДДДДДРДДДДДДДРДДДДДРДДДДДДДДДДДДДДДЅ"<<endl; system("pause"); fwrite(pstud, sizeof(student), 1, pfile); cout << "Dannie v fail zapisani"; fclose(pfile); } void fpoisk (student *pstud) { char s[] = "blondin*"; int r=0; bool f=true; for (int i=1; i<=n; i++) { if (pstud->rost>r) { r=pstud->rost; } } cout<<endl<<endl<<endl; if (s==pstud->cvet && r==pstud->rost); { cout<<" Familiya: "<<pstud->fam<<endl; cout<<" Rost: "<<pstud->rost<<endl; cout<<" Ves: "<<pstud->ves<<endl; cout<<" Cvet volos: "<<pstud->cvet<<endl; f=false; } system("pause"); } void freadfromfile (char *file_name) { student *stud = new student[n]; int i=1; FILE *pFile = fopen(file_name,"rb"); cout << "Informatsiya o studentah: " << endl; while(!feof(pFile)){ fread(stud, sizeof(student), 1, pFile); if (!feof(pFile)){ cout <<i<< ": " << endl; cout << "Familiya: " << stud->fam << endl; cout << "Rost: " << stud->rost << endl; cout << "Ves: " << stud->ves << endl; cout << "Cvet volos: "<< stud->cvet<<endl; system ("pause"); i++; } } fclose(pFile); delete[] stud; } 
  • You declare variables in functions such as int i and bool f, then you change their values, but they are not static, so you cannot use them any further - they do nothing, and after calling the function they are destroyed. And why do we need the system command ("pause"); ? .. - AR Hovsepyan
  • one
    English would teach you some) - And

1 answer 1

void fpoisk (student *pstud) to the function you need to pass the dimension of the array pointed to by pstud . The function does not know anything about your intention to declare the dimension in the variable 'n' in main () . But you use this variable in the function, the compiler should swear ... And you do not need to declare the s array, initialize it, and then compare it with pstud->cvet , but you can immediately write if (pstud->cvet =="blondin*" && r==pstud->rost); By the way, here you need to delete the ';' Well, in principle, a lot of things confused with you. In the loop, you do not increment the pointer and constantly compare with the same element, and so on.