943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2172
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 22nd, 2009
0

vowels,consonants and special symbols

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  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. }
Reputation Points: 8
Solved Threads: 0
Junior Poster
jeevsmyd is offline Offline
136 posts
since Oct 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

first, format the code so that it uses proper indentation, and braces. That's the first step.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

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
Reputation Points: 8
Solved Threads: 0
Junior Poster
jeevsmyd is offline Offline
136 posts
since Oct 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

what is it supposed to do ,bro??
Reputation Points: 10
Solved Threads: 5
Light Poster
arghasen is offline Offline
35 posts
since Nov 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

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
Reputation Points: 10
Solved Threads: 5
Light Poster
arghasen is offline Offline
35 posts
since Nov 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

Friends I cant thank you enough for your help and guidance.. Am working hard to become a C++ programmer
Reputation Points: 8
Solved Threads: 0
Junior Poster
jeevsmyd is offline Offline
136 posts
since Oct 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 8
Solved Threads: 0
Junior Poster
jeevsmyd is offline Offline
136 posts
since Oct 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

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();
}
Reputation Points: 10
Solved Threads: 5
Light Poster
arghasen is offline Offline
35 posts
since Nov 2008
Feb 22nd, 2009
0

Re: vowels,consonants and special symbols

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
Reputation Points: 10
Solved Threads: 5
Light Poster
arghasen is offline Offline
35 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: cannot convert parameter
Next Thread in C++ Forum Timeline: no appropriate default constructor available :(





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC