#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int getline(char s[], int lim){
	int i, c;
	for (i=0; i<lim && (c=getchar()) != EOF && c != '\n'; ++i) {
		s[i] = c;
	}
	s[i] = '\0';
	return (i);
}



int neve(char s[])
{
int i, h, ok=1, hiba=0;
h=strlen(s);

for(i=0;i<h;i++){

	if(!isalpha(s[i]) || !islower(s[i])){ok=0;}
}


if(ok==0){
for(i=0;i<h;i++)
{
	if(!isalpha(s[i]) || !islower(s[i])){
		if(s[i]=='_' || s[i]=='-'){ok=1;}
		else{ok=0; hiba++;}
	}
}
}


if(ok==1){

for(i=0;i<h;i++)
{
	if(s[i]=='á' || s[i]=='û' || s[i]=='õ' || s[i]=='ú' || s[i]=='ó' || s[i]=='ü' || s[i]=='ó' || s[i]=='ö' || s[i]=='é' || s[i]==' ') {ok=0;}

}
}


if(hiba>0){ok=0;}
return ok;
}




int szame(char kor[]){
int ok=1, h, i, n=0;
h=strlen(kor);

for(i=0;i<h;i++)
{
	if(!isdigit(kor[i])){ok=0;}
}

if(ok==1)
{
n=atoi(kor);
}

if(n<0 || n>100){ok=0;}


return ok;
}


void main(void)
{
int ok=1,k=0,l=0, i=0, h=0, a=0, b=0, db=0;
float atlag=0;
char s[128];
char kor[128];
char nevek[128];
char seged[128];

printf("\tNevatalkito\n\n");


do{

do{
ok=1,i=0,h=0, l=0;
printf("Adjon meg egy nevet:\n");

h=getline(s,128);

if(h>0){
if(neve(s)){ok=1; printf("Jo\n");}
else{ok=0; printf("Nem jo, adjon meg ujat!\n");}
}
}while(ok!=1);



if(ok==1 && h>0){
do{
printf("%c", toupper(s[l]));
l++;

while(isalpha(s[l])){
printf("%c",s[l]);
l++;}


if(s[l]=='_'){printf(" ");l++;}
if(s[l]=='-'){printf("-");l++;}

printf("%c", toupper(s[l]));
l++;

while(isalpha(s[l])){
printf("%c",s[l]);
l++;}

if(s[l]=='_'){printf(" "); l++;}
if(s[l]=='-'){printf("-"); l++;}

}while(l<h);

}


do{
a=0;
printf("\nAdja meg az eletkorat:\n");


h=getline(kor,128);
if(h!=0){

if(szame(kor)){
	ok=1; 
	a=atoi(kor); 
	b=b+a;
	db++;

}
else{ok=0; printf("Nem jo\n");}
}

}while(ok!=1);

}while(h!=0);

(float) atlag=(float) b/(float) db;

	printf("Atlag eletkor: %0.2f\n", atlag);

}
