I am trying to fix this program. It should count from the text entered how many alphabets in uppercase and lowercase, digits, blank spaces and 'other symbols'.
This is the program below. Please correct the mistakes please..!!
#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++;
elseif(islower(text[i]))
nl++;
elseif(isdigit(text[i]))
nd++;
elseif(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();
}
-first error you didn't use usingnamespace std; or using std::cout and using std::cout or std::cin/std::cout
-second error:elseif instead of elseif
-third error:line 21:
elseif(text[i]==' '))
you have to write:elseif(text[i]==' ')) //only one space between ' '
also where is the for loop ending:there should be a } on line 25
"counting - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
Nothing to be done.
#include <iostream>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
usingnamespace std;
int 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++;
elseif(islower(text[i]))
nl++;
elseif(isdigit(text[i]))
nd++;
elseif(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();
}}
with void main
and deleting the return 0;
eliminated the warning too....
now compiled and runs..!!!
but I am not getting correct answers....its just giving lowercase alphabets 1 no matter whatever i types....
and when i press enter it doesnt close the window but again gives out repeadtedly.
#include <iostream>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
usingnamespace std;
int main()
{
//no clrscr() because it isn't present in Microsoft VS2010(at least at my knowledge) (and no need to use it here for it)
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++;
elseif(islower(text[i]))
nl++;
elseif(isdigit(text[i]))
nd++;
elseif(text[i]==' ') //corrected here
nb++;
else
ns++;
} //and here
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();
}//and here