Hi all,
I am beginner in C. I tried to write a code using struct and typedef [as written below] but I can't get the result as I wanted to. Is there anybody out there can help and show me why I failed to run my program....?
------------------------------------------------------------
I am beginner in C. I tried to write a code using struct and typedef [as written below] but I can't get the result as I wanted to. Is there anybody out there can help and show me why I failed to run my program....?
------------------------------------------------------------
Code:
#include <stdio.h>
#include <string.h>
#define MAX 10
int i, agedata, Num, x, y;
char telnodata[11], namedata[20];
struct callersinfo
{
char callername[20];
char telno[11];
int age;
};
typedef callersinfo callperson;
callperson caller[10];
int main()
{
printf("\nFIRE BRIGADE DEPARTMENT");
for(i=0;i<MAX;i++)
{
Num=Num++;
printf("\n\nName: ");
scanf("%s",&namedata);
printf("Tel. No: ");
scanf("%d",&telnodata);
printf("Age: ");
scanf("%d",&agedata);
if (agedata<10)
{
printf("Type of call: 2");
printf("\nTHE CALL MAY BE FAKE. BE CAUTIOUS!\n");
}
else
if (agedata>=10)
{
printf("Type of call: 1");
printf("\nTHE CALL IS A GENUINE EMERGENCY CALL\n");
}
strcpy (caller[i].callername,namedata);
strcpy (caller[i].telno,telnodata);
caller[i].age=agedata;
}
for(i=0;i<MAX;i++)
{
printf("\nName: %s",caller[i].callername);
printf("\nTel. No: %s",caller[i].telno);
printf("\nAge: %d",caller[i].age);
if (caller[i].age<10)
{
printf("\nType of call: 2");
printf("\nTHE CALL MAY BE FAKE. BE CAUTIOUS!\n");
x=x++;
}
else
if (caller[i].age>=10)
{
printf("\nType of call: 1");
printf("\nTHE CALL IS A GENUINE EMERGENCY CALL\n");
y=y++;
}
}
printf("\nSummary:");
printf("\nTotal number of callers: %d",Num);
printf("\nNumber of genuine emergency calls: %d",y);
printf("\nNumber of fake calls: %d",x);
return 0;
}
Comment