File does not work.Does not record information.Please help!
-Enter of a keyboard and a file into an array (by adding) data to 30 girls
#include <iostream>
#include<fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
#define N 30
FILE *fp;
struct girl
{
char number[10];
int age;
int bust ;
char height[20];
char hip[20];
char waist[20];
char weight[20];
}
gr[N];
int top=0;
int menu()
{
int ch;
cout<<"\n_______________MENU________________";
cout<<"\n 1. Input number of girls";
cout<<"\n 2. Display list of all girls";
cout<<"\n 3. Display girls under 20";
cout<<"\n 4. Girl largest bust ";
cout<<"\n 5. Search by number:";
cout<<"\n 6. Exit";
do
{
cout<<"\n Choice: ";
cin>>ch;
}
while(ch<1||ch>6);
return(ch);
}
void load()
{
if ((fp=fopen("my.txt","rb"))==NULL)return;
if (fread(&top, sizeof top, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
if(fread(gr, sizeof gr, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
fclose(fp);
}
void save()
{
if ((fp=fopen("my.txt", "wb"))==NULL)
{cout<<"\n error"; exit(1);}
if(fwrite (&top,sizeof top, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
if(fwrite (gr, sizeof gr, 1, fp)!=1)
{cout<<"\n Error"; exit(1);}
fclose(fp);}
void disp(int n)
{
cout<<"\n Number: "<<gr[n].number;
cout<<"\n Age: "<<gr[n].age;
cout<<"\n Waist: "<<gr[n].waist;
cout<<"\n Hip: "<<gr[n].hip;
cout<<"\n buist: "<<gr[n].bust;
cout<<"\n weight:"<<gr[n].weight;
cout<<"\n height:"<<gr[n].height;
}
void info()
{
int i;
cout<<"\n Spisyk: \n";
for(i=0; i<top; i++)
disp(i);
}
void enter()
{
int count=0,n, i, ost;
ost=N-top;
if(ost>0)
{cout<<"\n There is room for more"<<ost<<" contestants";
{
cout<<"\n New contestants:";cin>>count;}
while (count<0 || count>ost);
for (i=top; i<top+count; i++)
{
cout<<"\n Number: ";
cin>>gr[i].number;
cout<<"\n Age: ";
cin>>gr[i].age;
cout<<"\n hip: ";
cin>>gr[i].hip;
cout<<"\n waist: ";
cin>>gr[i].waist;
cout<<"\n bust: ";
cin>>gr[i].bust;
cout<<"\n weight:";
cin>>gr[i].weight;
cout<<"\n height:";
cin>>gr[i].height;
}
top=i;
}
else cout<<"Error.";
}
void list()
{
int i;
cout<<"\n List\n";
for(i=0;i<top;i++)
disp(i);
}
void teen()
{
int i;
cout<<"\n Girls under 20\n";
for(i=0;i<top;i++)
{gr[i].age*=1;
if(gr[i].age<20)
disp(i);
}
}
void showgirl(girl gr[N])
{
char t_number[10];
int i, found;
fflush(stdin);
cout<<"\n Search by number \n ";
cout<<"\n number \n";
cin>>t_number;;
found=0;
for(i=0; i<top; i++){
if(!strcmp(t_number, gr[i].number)) {
disp(i);
found=1;
}
}
if(!found){
cout<<"\n Error. ";
}
}
void bust()
{int fb=0,pos=0,i;
{
string im;
string ifn;
int max=500;
for(int r=0;r<fb;r++)
{
if(gr[r].bust<max)
{
max=gr[r].bust;
im=gr[r].number;
}
}
cout<<"\n Girl largest bust :"<< "\n "<<gr[i].number<<"\t"<<gr[i].age<<"\t"<<gr[i].waist<<"\t"<<gr[i].hip<<"\t"<<gr[i].bust<<"\t"<<gr[i].height<<"\t"<<gr[i].weight<<"\t"<<endl;
for(i=0;i<pos;i++)
for(int j=0;j<pos-i-1;j++)
if(gr[j].bust>gr[j+1].bust)
{
girl c=gr[j];
gr[j]=gr[j+1];
gr[j+1]=c;
}
cout<<"\n "<<endl;
for(int y=0;y<pos;y++)
cout<<gr[y].number<<" "<<gr[y].bust<<endl;
}
}
int main()
{ int ch;
load();
do
{ ch=menu();
switch(ch)
{
case 1: enter();break;
case 2: list();break;
case 3: teen();break;
case 4: showgirl(gr);break;
case 5: bust( );break;
}}
while (ch!=6);
}