i'm newbie in c programming langauge
i created program that insert employes data and then print their data
but never accept duplicate age if user entered duplicated age promot him to enter another age (age must be unique)
here is my code
Code:
#include<conio.h>
#include<stdio.h>
#define size 3
struct emp
{
int age,overtime,dedcution,netsal;
float salary;
char firstname[15];
char lastname[15];
};
int main()
{
int i,j,unq=1,arr[3]={0};
float temp=0.0;
struct emp employes[3];
clrscr();
printf("please insert data of employee\n");
for(i=0;i<size;i++)
{
clrscr();
gotoxy(5,2);
printf("firstname");
gotoxy(40,2);
printf("lastname");
gotoxy(5,4);
printf("age");
gotoxy(40,4);
printf("salary");
gotoxy(5,6);
printf("overtime");
gotoxy(40,6);
printf("nset salary");
gotoxy(16,2);
scanf("%s", employes[i].firstname);
gotoxy(50,2);
scanf("%s",employes[i].lastname);
gotoxy(10,4);
scanf("%d",&employes[i].age);
arr[0]=employes[0].age;
for(j=i+1;j<size;j++)
{
if(arr[i] == employes[j].age )
{
unq=0;
break;
}
}
if(unq==0)
{
gotoxy(10,4);
scanf("%d",&employes[i].age);
}else{
arr[i]=employes[i+1].age;
}
/*
for(j=i+1;j<size;j++)
{
if(arr[i] == employes[j].age)
{
unq=0;
break;
}
}
if(!unq) unq=1; goto Ask;
*/
gotoxy(50,4);
scanf("%f",&temp);
// employes[i].salary=0;
employes[i].salary =temp;
gotoxy(20,6);
scanf("%d",&employes[i].overtime);
gotoxy(55,6);
scanf("%d",&employes[i].netsal);
}
clrscr();
for(i=0;i<size;i++)
{
printf("first name :\t %s \n",employes[i].firstname);
printf("last name :\t %s \n ",employes[i].lastname);
printf("age:\t %d \n",employes[i].age);
printf("salary:\t %f \n",employes[i].salary);
printf("overtime:\t %d \n",employes[i].overtime);
printf("netsal :\t %d \n",employes[i].netsal);
printf("\n _______________________ \n");
}
getch();
return 0;
}