读书人

,多谢各位

发布时间: 2012-02-25 10:01:47 作者: rapoo

求助,谢谢各位
我写了以下程序,但没有达到我想要的效果,不知道怎么回事,请高手帮忙分析一下,谢谢
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');
}

[解决办法]

C/C++ code
#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;}
[解决办法]
C/C++ code
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'); }
[解决办法]
C/C++ code
//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'); } 

读书人网 >C语言

热点推荐