求助,谢谢各位
我写了以下程序,但没有达到我想要的效果,不知道怎么回事,请高手帮忙分析一下,谢谢
void main()
{int x;
char i,ans;
ans='y';
do
{ x=0;
printf("\nplease input letters:");
do
{ i=getchar();
x++;
}while(i!='\n');
printf("\nthe sum of letters is:%d",--x);
printf("\ndo you want to input more letters?(Y/y)");
ans=getchar();
}while(ans=='Y'||ans=='y');
}
[解决办法]
#include<stdio.h>int main(){int x; char i,ans; ans='y'; do { x=0; printf("\nplease input letters:"); do { i=getchar(); x++; }while(i!='\n'); printf("\nthe sum of letters is:%d",--x); printf("\ndo you want to input more letters?(Y/y)"); ans=getchar(); getchar(); }while(ans=='Y'||ans=='y'); return 0;}
[解决办法]
void main() {int x; char i,ans; ans='y'; do { x=0; printf("\nplease input letters:"); getchar(); do { i=getchar(); x++; }while(i!='\n'); printf("\nthe sum of letters is:%d",--x); printf("\ndo you want to input more letters?(Y/y)"); ans=getchar(); }while(ans=='Y' ¦ ¦ans=='y'); }
[解决办法]
//lz啊,要注意,getchar()这个函数是认识空格和换行符的,你得用其他的//给这个程序,是要你明白一下#include <stdio.h>#include <stdlib.h>void main() {int x; char i,ans; ans='y'; do { x=0; printf("\nplease input letters:"); do { i=getchar(); x++; }while(tolower(i)!='n'); //tolower(i)将i转换为小写 printf("\nthe sum of letters is:%d",--x); printf("\ndo you want to input more letters?(Y/y)"); getchar(); ans=getchar(); }while(ans=='Y' ||ans=='y'); }