2014-01-16 37 views
-9

我想编译和TURBOC运行此++,我正则表达式语法错误在行 否则,如果(文[I] ==”“))表达式语法错误TURBOC++

我也试图在代码块只有很小的改动,但它返回“counting - Debug”使用了一个无效的编译器。编译器选项中的工具链路径可能没有正确设置?跳过... 没有事可做。

反正我的主要目的是使其在TURBOC++

#include<iostream.h> 
#include<conio.h> 
#include<stdio.h> 
#include<ctype.h> 

void main() 
{ 
    clrscr(); 
    int nu,nl,nd,nb,ns; 
    char text[100]; 
    nu=nl=nd=nb=ns=0; 
    cout<<"enter a line of text\n"; 
    cin>>text; 
    for(int i=0;text[i]!='\0';i++) 
    { 
    if(isupper(text[i])) 
     nu++; 
    else if(islower(text[i])) 
     nl++; 
    else if(isdigit(text[i])) 
     nd++; 
    else if(text[i]==' ')) 
     nb++; 
    else 
    ns++; 
    cout<<"total number of uppercase alphabets="<< nu << ".\n"; 
    cout<<"total number of lowercase alphabets="<< nl << ".\n"; 
    cout<<"total number of digits="<< nd << ".\n"; 
    cout<<"total number of blank spaces="<< nb << ".\n"; 
    cout<<"total number of other symbols="<< ns << ".\n"; 
    getch(); 
} 
+2

有太多了) – deviantfan

+2

我会推荐刷新如何格式化你的代码,它也将有助于你使用一个IDE,将轻松地匹配打开/关闭括号/ parens /等。 – admdrew

+0

雅是一个愚蠢的错误,但为什么我得到的答案错误时,我输入文字的数字和字母... – neonano

回答

4
else if(text[i]==' ')) 

您这里有一个额外的右括号

+0

只是现在只有我解决了... – neonano

0

好吧,我已经找到解决错误的答案的所有问题而被拘留屡次和其他代码错误..这是最终的代码..!

#include<iostream.h> 
#include<conio.h> 
#include<stdio.h> 
#include<ctype.h> 

void main() 

{ 
//clrscr(); 
int nu,nl,nd,nb,ns; 
char text[100]; 
    nu=nl=nd=nb=ns=0; 
    cout<<"Enter a line of text.\n"; 
    gets(text); 
    for(int i=0;text[i]!='\0';i++) 
    { 
     if(isupper(text[i])) 
      nu++; 
     else if(islower(text[i])) 
      nl++; 
     else if(isdigit(text[i])) 
      nd++; 
     else if(text[i]==' ') 
      nb++; 
     else 
      ns++; 
} 
cout<<"total number of uppercase alphabets="<<nu<< ".\n"; 
cout<<"total number of lowercase alphabets="<<nl<< ".\n"; 
cout<<"total number of digits="<<nd<< ".\n"; 
cout<<"total number of blank spaces="<<nb<< ".\n"; 
cout<<"total number of other symbols="<<ns<< ".\n"; 
getch(); 
} 
0

您的for循环缺少一个闭合大括号。