# c++关于while,continue的问题

0
[待解决问题]

#include<iostream>
int main()
{
int n=0;
char c;
c=std::cin.get();
while(c!='\0'){
if((c>'A'&&c<'Z')||(c>'a'&&c<'z'))n++;
continue;
}
std::cout<<n;
}

qianyu | 菜鸟二级 | 园豆：202

0

continue去掉没任何影响.

@qianyu: 打断点没有..c的值是多少.

@吴瑞祥: 那这个程序该如何编写呢

1

1.首先空格并不是\0,ASCII码是32

2.其次应该是c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z'

jello chen | 园豆：7101 (大侠五级) | 2017-03-19 22:35
0

1，while 循环条件写的十分有问题

2，在循环体中没有迭代，是个死循环

0
``` 1 #include<iostream>
2 int main()
3 {
4     int n = 0;
5     char c;
6     c = std::cin.get();
7     //while( c!='\0' )
8     while( c!=' ' )
9     {
10         //if( ( c>'A' && c<'Z') || ( c>'a'  && c<'z' ) ) //AaZz will not be counted
11         if( ( c>='A' && c<='Z') || ( c>='a'  && c<='z' ) )
12             n++;
13         //continue;
14         // get next input
15         c = std::cin.get();
16     }
17     std::cout<<n;
18 }```

``` 1 #include<iostream>
2 int main()
3 {
4     int n = 0;
5     char c = 0;
6     do
7     {
8         c = std::cin.get();
9         if( ( c>='A' && c<='Z') || ( c>='a'  && c<='z' ) )
10         {
11             n++;
12         }
13     } while(c != ' ');
14     std::cout << n;
15     return 0;
16 }```
++C+C++ | 园豆：202 (菜鸟二级) | 2017-03-23 13:22
0

```#include<iostream>
int main()
{
int n = 0;
char c;
c = std::cin.get();
while( c!=' ' )
{

if( ( c>='A' && c<='Z') || ( c>='a'  && c<='z' ) )
n++;
c = std::cin.get();
}
std::cout<<n;
}```

fcyh | 园豆：568 (小虾三级) | 2017-07-04 16:49
0

MyCPlusPlus | 园豆：43 (初学一级) | 2017-08-29 10:59
0

```int main()
{
string s;
cin >> s;
//do sth.
}```
Aehnuwx | 园豆：263 (菜鸟二级) | 2018-07-10 11:57
0

# include<iostream>

int main()
{
int n=0;
char c;
while(c!=' '){
c=std::cin.get();
if((c>'A'&&c<'Z')||(c>'a'&&c<'z'))n++;
}
std::cout<<n;
}

beelake | 园豆：218 (菜鸟二级) | 2019-03-17 19:30

您需要登录以后才能回答，未注册用户请先注册