| | |
vowels,consonants and special symbols
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi friends.. Last day at school my teacher gave the following code.. But it is not working.. 16 errors.. I am a beginner in C++ .I badly need your guidance a help in finding the errors... the for loops is all wrong.. To be frank I don't understand the working of this program.. please help me understand it,wont you?
here is the code
here is the code
C++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> #include<string.h> void main() { char line[80]; int k,len,vow,cons,sp; cout<<"Enter the string "; cin.getline(len i,80); for(i=0;line[len]!=10;len++) { if (line[k]!=" ") if(line[k]=="A"||line[k]=="E"||line[k]=="I"||line[k]=="O"||line[k]=="U"||line[k]=="a"||line[k]=="e"||line[k]=="o"||line[k]=="u"); vow++; else if(( line [k]>='A'&&line[k]<='Z')||(line[k]>='a'&&line[k]<='z')) cons++; else sp++; { cout<<"no of vowels = "<<vow; cout<<"number of constants ="<<cons; cout<<"No of special characters ="<<sp; getch(); }
I guess the lessons of the previous thread haven't sunk in yet.
http://www.daniweb.com/forums/thread177531.html
Here's how to start
Now press compile AND make sure it works.
Now add a few (not ALL) of your lines of code for the loop body, and try to compile it again.
Also learn to put { } on ALL your for loops, while loops, if statements and switch/case statements. It'll save you from spending ages finding yet another stupid bug because the code did what you asked it to, not what you thought you wanted.
http://www.daniweb.com/forums/thread177531.html
Here's how to start
for(i=0;line[len]!=10;len++) { }
Now add a few (not ALL) of your lines of code for the loop body, and try to compile it again.
Also learn to put { } on ALL your for loops, while loops, if statements and switch/case statements. It'll save you from spending ages finding yet another stupid bug because the code did what you asked it to, not what you thought you wanted.
C++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> #include<string.h> void main() { char line[80]; int k,len,vow,cons,sp; cout<<"Enter the string "; cin.getline(len i,80); for(i=0;line[len]!=10;len++) { if (line[k]!=" ") if(line[k]=='A'||line[k]=='E'||line[k]=='I'||line[k]=='O'||line[k]=='U'||line[k]=='a'||line[k]=='e'||line[k]=='i'||line[k]=='o'||line[k]=='u'); vow++; else if(( line [k]>='A'&&line[k]<='Z')||(line[k]>='a'&&line[k]<='z')) cons++; else sp++; { cout<<"no of vowels = "<<vow; cout<<"number of constants ="<<cons; cout<<"No of special characters ="<<sp; getch(); }
I made some corrections.. now what is use of "i" ? Now there are 6 more errors.. It says that undefined symbol i ... Do reply buddies
•
•
Join Date: Nov 2008
Posts: 29
Reputation:
Solved Threads: 4
take the code i give
u will understand urself
u will understand urself
#include<iostream.h>
#include<conio.h>
#include<string.h>
int main()
{
char line[80];
int k,len,vow=0,cons=0,sp=0,i;
cout<<"Enter the string ";
gets(line);
for(k=0;line[k]!='\0';k++)
{
if (line[k]!=32 )//Ascii code for blank
{
if(line[k]=='A'||line[k]=='E'||line[k]=='I'||line[k]=='O'||line[k]=='U'||line[k]=='a'||line[k]=='e'||line[k]=='o'||line[k]=='u')
vow++;
else if(( line [k]>='A'&&line[k]<='Z')||(line[k]>='a'&&line[k]<='z'))
cons++;
else sp++;
}
}
cout<<"no of vowels = "<<vow;
cout<<"number of constants ="<<cons;
cout<<"No of special characters ="<<sp;
getch();
}![]() |
Other Threads in the C++ Forum
- Previous Thread: cannot convert parameter
- Next Thread: no appropriate default constructor available :(
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






