vowels,consonants and special symbols

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

vowels,consonants and special symbols

 
0
  #1
Feb 22nd, 2009
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
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. void main()
  5. {
  6. char line[80];
  7.  
  8. int k,len,vow,cons,sp;
  9. cout<<"Enter the string ";
  10. cin.getline(len i,80);
  11. for(i=0;line[len]!=10;len++)
  12. {
  13. if (line[k]!=" ")
  14. 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");
  15. vow++;
  16.  
  17. else if(( line [k]>='A'&&line[k]<='Z')||(line[k]>='a'&&line[k]<='z'))
  18. cons++;
  19. else sp++;
  20. {
  21. cout<<"no of vowels = "<<vow;
  22. cout<<"number of constants ="<<cons;
  23. cout<<"No of special characters ="<<sp;
  24. getch();
  25. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: vowels,consonants and special symbols

 
0
  #2
Feb 22nd, 2009
first, format the code so that it uses proper indentation, and braces. That's the first step.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

Re: vowels,consonants and special symbols

 
0
  #3
Feb 22nd, 2009
Buddy.. the problem is that I don't understand the first part of the code,ie the for loop and len.. what is line k? please please help me...
then i will format it with braces and all
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: vowels,consonants and special symbols

 
0
  #4
Feb 22nd, 2009
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
for(i=0;line[len]!=10;len++) {
}
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: vowels,consonants and special symbols

 
0
  #5
Feb 22nd, 2009
what is it supposed to do ,bro??
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: vowels,consonants and special symbols

 
0
  #6
Feb 22nd, 2009
oh sorry i put up the post without refeshing my page,so didnt see that so many lesons have been put up for u already
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

Re: vowels,consonants and special symbols

 
0
  #7
Feb 22nd, 2009
Friends I cant thank you enough for your help and guidance.. Am working hard to become a C++ programmer
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 78
Reputation: jeevsmyd is an unknown quantity at this point 
Solved Threads: 0
jeevsmyd's Avatar
jeevsmyd jeevsmyd is offline Offline
Junior Poster in Training

Re: vowels,consonants and special symbols

 
0
  #8
Feb 22nd, 2009
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. void main()
  5. {
  6. char line[80];
  7.  
  8. int k,len,vow,cons,sp;
  9. cout<<"Enter the string ";
  10. cin.getline(len i,80);
  11. for(i=0;line[len]!=10;len++)
  12.  
  13. {
  14. if (line[k]!=" ")
  15. 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');
  16. vow++;
  17.  
  18. else if(( line [k]>='A'&&line[k]<='Z')||(line[k]>='a'&&line[k]<='z'))
  19. cons++;
  20. else sp++;
  21. {
  22. cout<<"no of vowels = "<<vow;
  23. cout<<"number of constants ="<<cons;
  24. cout<<"No of special characters ="<<sp;
  25. getch();
  26. }

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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: vowels,consonants and special symbols

 
0
  #9
Feb 22nd, 2009
take the code i give
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();
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: vowels,consonants and special symbols

 
0
  #10
Feb 22nd, 2009
the funcion gets does the job of taking the data in a line
i have not use cin.getline so i cant tell about that and the i in ur program is wrong it should be k as in my program
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC