[ back to toc ]

C programming relative to structure

Date: 2002/05/06 12:34

Q:
Hi, I am having problem with this programming that I have, please inform
me what to do, send me corrections if possible...

/*The Happy-Ever-After Dating Service maintains records of individuals
looking for dates.
Each record tracks an individual's sex, social security number, name, age,
occupation,
yearly income, major and minor hobbies, height, weight, and religion. The
recors are sorted by
SSN. The service matches individuals as follows: Two individuals mathc if
they are opposite in gender
and either a) are within 10 yrs of one another's age and within 10000 of
each other's income
or b) share both a major and a minor hobby. Write a program that reads a
SSn and writes the names
and attributes of all matching individuals.*/

#include <stdio.h>
#include <string.h>
typedef struct Record{
char name[30];
int age;
char sex[2];
int ssn;
char job[20];
int income;
char major_hobby[20];
char minor_hobby[20];
int height;
int weight;
char religion[10];
}record;
main()
{
record data[1],sorteddata[1],match[1];
int i=0,x=0,n=0,z=0;
char q[20];
do{
printf("Enter a name: ");
scanf("%s",&data[i].name);
printf("Enter his/her sex: ");
scanf("%s",&data[i].sex);
printf("Enter ssn: ");
scanf("%d",&data[i].ssn);
printf("Enter job: ");
scanf("%s",&data[i].job);
printf("Enter age: ");
scanf("%d",&data[i].age);
printf("Enter income: ");
scanf("%d",&data[i].income);
printf("Enter height: ");
scanf("%d",&data[i].height);
printf("Enter weight: ");
scanf("%d",&data[i].weight);
printf("Enter religion: ");
scanf("%s",&data[i].religion);
printf("Enter major hobby: ");
scanf("%s",&data[i].major_hobby);
printf("Enter minor hobby: ");
scanf("%s",&data[i].minor_hobby);
i++;
}while(i<=1);
for( n=0;n<i;n++)
{
for(x=0;x<i;x++)
if(data[n].ssn > data[x].ssn)
z++;
sorteddata[z].ssn=data[n].ssn;
sorteddata[z].height=data[n].height;
sorteddata[z].income=data[n].income;
sorteddata[z].age=data[n].age;
strcpy(sorteddata[z].job,data[n].job);
strcpy(sorteddata[z].major_hobby,data[n].major_hobby);
strcpy(sorteddata[z].minor_hobby,data[n].minor_hobby);
strcpy(sorteddata[z].name,data[n].name);
strcpy(sorteddata[z].religion,data[n].religion);
strcpy(sorteddata[z].sex,data[n].sex);
sorteddata[z].weight=data[n].weight;
z=0;
}
printf("%d\n",sorteddata[0].ssn);
printf("%d\n",sorteddata[1].ssn);
printf("SSN Age Name Sex Income Job Religion Ma-hobby Mi-hobby
Height Weight\n");

for(n=0;n<i;n++)
{
printf("%9d",sorteddata[n].ssn);
printf("%3d",sorteddata[n].age);
printf("%7s",sorteddata[n].name);
printf(" %3s",sorteddata[n].sex);
printf(" %7d",sorteddata[n].income);
printf(" %5s",sorteddata[n].job);
printf(" %8s",sorteddata[n].religion);
printf(" %8s",sorteddata[n].major_hobby);
printf(" %10s",sorteddata[n].minor_hobby);
printf(" %5d",sorteddata[n].height);
printf(" %5d\n",sorteddata[n].weight);
}
int ssn,k=1;
printf("Enter a social security number: ");
scanf("%d",&ssn);
for(n=0;n<i;n++)
{
if(sorteddata[n].ssn==ssn)
match[0]=sorteddata[n];
}
for(n=0;n<i;n++)
{
if((sorteddata[n].sex!=match[0].sex) &&
(sorteddata[n].ssn!=match[0].ssn))
{
if((sorteddata[n].age-match[0].age<=10) &&
(sorteddata[n].income-match[0].income<=10000))
match[k]=sorteddata[n];
else if ((sorteddata[n].major_hobby ==match[0].minor_hobby) &&
(sorteddata[n].minor_hobby==match[0].minor_hobby))
match[k]=sorteddata[n];
k++;
}

}
printf("SSN Age Name Sex Income Job Religion Ma-hobby Mi-hobby
Height Weight\n");
for(n=0;n<k;n++)
{
printf("%9d",match[n].ssn);
printf("%3d",match[n].age);
printf("%7s",match[n].name);
printf(" %3s",match[n].sex);
printf(" %7d",match[n].income);
printf(" %5s",match[n].job);
printf(" %8s",match[n].religion);
printf(" %8s",match[n].major_hobby);
printf(" %10s",match[n].minor_hobby);
printf(" %5d",match[n].height);
printf(" %5d\n",match[n].weight);
}
}

Thank you!

A:
Could you give some specific question, qhat your problem is actually?

Peter

[ back to toc ]