Compile program functions for:
-Enter of a keyboard and a file into an array (by adding) data to 30 girls in the competition "Miss World"
number, name, surname, date of birth, physical data, state and display the current contents of the array on the screen
-display output data for a girl by entered from the keyboard a number ( by request
a new report ).
-Displays data for the youngest girl in the competition and the number of girls under the age of 20 years.
Home-function main () menu selection functions and check the status of the data using the Global
variables or functions with transmission parameters, optional

I have a code but how to display youngest girl ?? Please help!

#include <iostream>
using namespace std;
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#define N 30 

typedef struct
{
   char number[10];
   char name[10];
   char family[10];
   int age;
   float height;
   float weight;
   char country[3];
} girl;

girl d[N];
int top=0;
float height;
float weight;

void load();
void save();
void nomer();

void input()
{
   int i, n;
   do
   {
       cout<<"\n Whats the number of girls: ";
       cin>>n;
   }
   while (n<1||n>N);
   fflush(stdin);
   for(i=top;i<n;i++)
   {
       cout<<"\n Number: ";
       cin>>d[i].number;
       cout<<"\n Name: ";
       cin>>d[i].name;
       cout<<"\n Family: ";
       cin>>d[i].family;
       cout<<"\n Age: ";
       cin>>d[i].age;
       cout<<"\n Height(cm): ";
       cin>>d[i].height;
       cout<<"\n Weight(kg): ";
       cin>>d[i].weight;
       cout<<"\n Country: ";
       cin>>d[i].country;
   }
   top+=n;
}


void disp(int i) //Display data for 1 girl
{
   cout<<"\n "<<d[i].number<<"\t"<<d[i].name<<"\t"<<d[i].family<<"\t"<<d[i].age<<"\t"<<d[i].height<<"\t"
       <<d[i].weight<<"\t"<<d[i].country<<endl;
}

void list() //List of girls
{
   int i;
   cout<<"\n List of girls\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++)
   {
       d[i].age*=1;
       if(d[i].age<20)
           disp(i);
   }
}

void number()

{
char t_number[10];

int i, found;


fflush(stdin);
cout<<"\n display data for 1 girl by entered number \n ";
cout<<"\n enter number \n";
cin>>t_number;;     
found=0;
for(i=0; i<top; i++){
if(!strcmp(t_number, d[i].number)) {
disp(i);
found=1;

}
}
if(!found){
cout<<"\n wrong number. ";
}
}
void age()
{

 girl max; girl min;  int i; 

 max.age = d[0].age; 
 for (int i = 1;i < 0; i++) 
 if (d[i].age > max.age) 
 max = d[i]; 

 cout << "Youngest girl: "<< max.name << max.family << max.age << max.height << max.weight << max.country;



 }
void load() 
{
   FILE *fp;
}

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. Display data for 1 girl by entered number";
   cout<<"\n 5. Display youngest girl ";
   cout<<"\n 6. Exit:";

   do
   {
       cout<<"\n Choice: ";
       cin>>ch;
   }
   while(ch<1||ch>6);
       return(ch);
}

int main()
{
   int i;
   cout<<"\n Loading file\n";
   load();
   do
   {
       i=menu();
       switch(i)
       {
       case 1: input();break;
       case 2: list();break;
       case 3: teen();break;
       case 4:number();break;
       case 5:age();break;



      }

   }
           while(i!=6);
return 0;
}

You could create an int to store the age and an int to store the index.

Set the age int to something unrealistically high ( 100 perhaps ) then as you loop compare the persons age with the stored current min age, if it's smaller store the age and the index.

Then print the person in the index.

Rather than set the lowest_found value to some abritrary high value, set it to the age of the first girl in the list. Then compare from the second one on. By setting the initial value to a valid data item, your code will be correct no matter what the range of ages.

Also, your extensive use of global variables is not good style. You should learn to pass the data between functions via the parameters and return values.

This article has been dead for over six months. Start a new discussion instead.