urgent help for c++ homework..

Hi,
Im new here.i need help about the boolean func. as a first step i wrote the below part. it actually at first check the length then the characters but the charcheck bool function does not work how can i do that? thanks.


void ToUpper(string & name);
void ToLower(string & name);
bool charcheck(string,string);


bool lencheck(string chars,string name)
{
bool y=false;

int len=chars.length();
if(len==10)
{
return y=true;
}
else
{
cout<<"Incorrect length!"<<endl;
return false;
cout<<name<<", please enter the character set: ";
cin>>chars;
}
return y;
}

bool charcheck(string chars,string name)
{
bool x=false;
int len=chars.length();
int i=0;//gives the location of the character


for(i=0;i<=len;i++)
{
if(((chars.at(i) >= 'a') && (chars.at(i) <= 'z')) || ((chars.at(i) >= 'A') && (chars.at(i) <= 'Z')))
{
return x=true;
}
else
{
cout<<"There are nonletter characters!"<<endl;
return x;
cout<<name<<", please enter another character set: "<<endl;
lencheck(chars,name);
}
}
return x;
}


int main()
{
string name,chars;
bool check=true;
cout<<"Please enter your name: "<<endl;
cin>>name;

name[0]=toupper(name[0]);
ToLower(name);

cout<<name<<", please enter the character set: ";
cin>>chars;
do{lencheck(chars,name);}while(true);
if(check=lencheck(chars,name))
{charcheck(chars,name);}
return 0;


}
Edit your post, hightlight all your code, then under the format option click the <> for source code.

Without that, your code is harder to read, and harder to comment on.
what is your char check function doing ? i assume it checks for the whole string to see if it has some non-alphabetic characters ? if yes, I have edited your for loop.. have a look.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
void ToUpper(string & name);
void ToLower(string & name);
bool charcheck(string,string);


bool lencheck(string chars,string name)
{
bool y=false;

int len=chars.length();
if(len==10)
{
return y=true;
}
else
{
cout<<"Incorrect length!"<<endl;
return false;
cout<<name<<", please enter the character set: ";
cin>>chars;
}
return y;
}

bool charcheck(string chars,string name)
{
bool x=false;
int len=chars.length();
int i=0;//gives the location of the character


bool flag = false;
for(i=0;i<=len;i++)
{
if(!isalpha(chars[i]))
{
flag = true;
break;
}
}

if(flag)
{
cout<<"There are nonletter characters!"<<endl;
}

return flag;
}


int main()
{
string name,chars;
bool check=true;
cout<<"Please enter your name: "<<endl;
cin>>name;

name[0]=toupper(name[0]);
ToLower(name);

cout<<name<<", please enter the character set: ";
cin>>chars;
do{lencheck(chars,name);}while(true);
if(check=lencheck(chars,name))
{charcheck(chars,name);}
return 0;


}


Also, statements after the return statement will have no meaning.
1
2
cout<<name<<", please enter the character set: ";
cin>>chars;


These two statements are pointless. They occur after the return statement, so they never get executed.
Topic archived. No new replies allowed.