I dont know what i am doing wrong , i am trying to validate a string entry (first name to only take lower and upper case letters) thru a function , but for some reason is not working ....=0(
Any idea why ?
This is the code
#include<iostre am>
using namespace std;
bool getstring (char[30]);
struct nameuser
{
char first[30];
char last [30];
};
struct studentype
{
nameuser name;
char nid [30];
float score;
};
void main()
{
studentype student [100];
float curve=0.0;
int i;
int nstudents;
bool validata;
do
{
cout<<"Enter the number of students [0-100]:";
cin>>nstudents;
if ((nstudents<1)| |(nstudents>100 ))
{
cout<<"Incorrec t value .Try Again !!"<<endl;
}
}while ((nstudents<1)| |(nstudents>100 ));
for (i=0;i<nstudent s;i++)
{
cout <<"Enter information for student#"<<i+1< <endl;
do
{
cout <<"First name :";
validata= getstring(stude nt[i].name.first);
if(!validata)
{
cout <<"Wrong input ...Try Again !!! \n";
}
}while (!validata);
cout <<"Last name :";
cin >>student[i].name.last;
cout <<"nid:";
cin >>student[i].nid;
cout <<"Enter score between [0-100]:";
cin >>student[i].score;
}
};
// function to check valid data:
bool getstring (char[]);
{
int i;
bool noerrors = true;
cin.getline (student[i].name.first,30) ;
i=0;
while ((i< strlen(student[i].name.first)) && noerrors)
{
if ((student[i].name.first<'A' ) || (student[i].name.first[i]>'z'))
{
lenght=strlen(s tudent[i].name.first);
noerrors=false;
}
i++;
}
return noerrors;
}
Any idea why ?
This is the code
#include<iostre am>
using namespace std;
bool getstring (char[30]);
struct nameuser
{
char first[30];
char last [30];
};
struct studentype
{
nameuser name;
char nid [30];
float score;
};
void main()
{
studentype student [100];
float curve=0.0;
int i;
int nstudents;
bool validata;
do
{
cout<<"Enter the number of students [0-100]:";
cin>>nstudents;
if ((nstudents<1)| |(nstudents>100 ))
{
cout<<"Incorrec t value .Try Again !!"<<endl;
}
}while ((nstudents<1)| |(nstudents>100 ));
for (i=0;i<nstudent s;i++)
{
cout <<"Enter information for student#"<<i+1< <endl;
do
{
cout <<"First name :";
validata= getstring(stude nt[i].name.first);
if(!validata)
{
cout <<"Wrong input ...Try Again !!! \n";
}
}while (!validata);
cout <<"Last name :";
cin >>student[i].name.last;
cout <<"nid:";
cin >>student[i].nid;
cout <<"Enter score between [0-100]:";
cin >>student[i].score;
}
};
// function to check valid data:
bool getstring (char[]);
{
int i;
bool noerrors = true;
cin.getline (student[i].name.first,30) ;
i=0;
while ((i< strlen(student[i].name.first)) && noerrors)
{
if ((student[i].name.first<'A' ) || (student[i].name.first[i]>'z'))
{
lenght=strlen(s tudent[i].name.first);
noerrors=false;
}
i++;
}
return noerrors;
}
Comment