Hi. Can I get some help?



for example:

How many members? 2

name: edward
birthday (mm dd yyyy): 12 28 1994

name: eddy
birthday (mm dd yyyy): 12 28 1994

Enter date: 12 28 1994

edward
eddy

here's my code.

#include<iostream>
#include<conio.h>
#include<string.h>

using namespace std;

int inmonth, inday, inyear;

typedef struct
{
int month;
int day;
int year;
}
date;

typedef struct
{
char name[50];
date birth;
}
record;

void writeoutput(record member);
record readinput(int i);

main()
{
system("cls");
int i,n;
record member[100];
record readinput (int i);
void writeoutput(record member);

cout << "\t\t\n\n";
cout << "How many members?:\t";
cin >> n;

for (i=0;i<n; ++i)
{
member[i]= readinput(i);

}

for (i=0;i<n;++i)
writeoutput(member[i]);

return 0;
}

record readinput (int i)
{
record member;
cout <<"\nMember number: "<<i+1;
cout <<"\nName: ";
cin >> member.name;
cout<<"Birthday (mm dd yyyy): ";
cin >>member.birth.month>>member.birth.day>>member.birth.year;


return(member);
}

void writeoutput(record member)
{
cout <<"\n\n\nEnter date (mm dd yyyy):\t";
cin >>inmonth>>inday>>inyear;
if (inmonth==member.birth.month&&inday==member.birth.day&&inyear==member.birth.year)
cout <<"\nName: "<<member.name;

getch ();
return;
}
Last edited on
What you need mate?
Do you want C++ help or C help? It looks like you're using a mix of both - choose one and stick with it.
Last edited on
After your readinput in main(), you will have to read another date. The one to search for in the list you just entered.

Thereafter you can loop through your list (what you already have) and only write output when the date of the current record matches the date you are searching for.

Something like


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* pseudo code */
main()
{
   readMemberCount() // like you're already doing

   for (i = 0; i < memberCount; ++i)
   {
      readinputs() // like you're already doing
   }

   readSearchDate() // this will be something new :)

   for (i = 0; i < memberCount; ++i)
   {
      if (searchDate == members[i].dateOfBirth)
      {
         writeOutput(members[i]);
      }
   }
}
hey demandred. I'm sorry but I still cant get it. Can you add it to my code. Please. I'm really having a hard time getting this one done.
#include<conio.h>
#include<string.h>
using namespace std;
int inmonth, inday, inyear;
typedef struct
{
int month;
int day;
int year;
}
date;
typedef struct
{
char name[50];
date birth;
}
record;
void writeoutput(record [],int);
record readinput(int i);
main()
{
system("cls");
int i,n;
record member[100];
cout << "How many members?:";
cin >> n;
for (i=0;i<n; ++i)
{
member[i]= readinput(i);
}
writeoutput(member,100);
getch();
return 0;
}
record readinput (int i)
{
record member;
cout <<"\nMember number: "<<i+1;
cout <<"\nName: ";
cin >> member.name;
cout<<"Birthday (mm dd yyyy): ";
cin >>member.birth.month>>member.birth.day>>member.birth.year;
return(member);
}
void writeoutput(record mem[],int size)
{
int count;
cout <<"\n\n\nEnter date (mm dd yyyy):\t";
cin >>inmonth>>inday>>inyear;
for(count =0;count<size;count++)
{
if (inmonth==mem[count].birth.month&&inday==mem[count].birth.day&&inyear==mem[count].birth.year)
cout <<"\nName: "<<mem[count].name;
}
}
Topic archived. No new replies allowed.