首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

,多谢各位

2012-02-25 
求助,谢谢各位我写了以下程序,但没有达到我想要的效果,不知道怎么回事,请高手帮忙分析一下,谢谢void main(

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

热点排行