PDA

View Full Version : is this correct?


psyche08
03-10-2005, 02:52 AM
here's my sample problem..
write a program to read text of line and output the list of all letters occur in text,together the number of times each letter occur the line.the letter should be listed in the order of most frequently occuring letter and next and so forth..use two parallel array,one is hold the letter and the other hold the number of lines that corresponding d letter.
ex.. do be do d=2
o=2
b=1
heres my program:\

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int main()
{
int bletter=0, eletter=0, aletter=0, uletter=0,tletter=0,iletter=0fletter=0, wletter=0,lletter=0,wdletter=0,notmatch=0;
char a;

clrscr();
cout<<"enter sentence:";
cin>>a;
if(wdletter % 12 ==0)
cout<<endl;
for(a=0;a<buf.size();a++)
{
switch(buf[a])
{
case'b':
++aletter;
break;
case'e':
++eletter;
break;
case'a':
++aletter;
break;
case'u':
++uletter;
break;
case't':
++tletter;
break;
case'i':
++iletter;
break;
case'f':
++fletter;
break;
case'w':
++wletter;
break;
case'l':
++lletter;
break;
default:
++notmatch;
break;
}
}
cout<<"\n\n";
<<"b:"<<bletter<<endl;
<<"e:"<<eletter<<endl;
<<"a:"<<aletter<<endl;
<<"u:"<<uletter<<endl;
<<"t:"<<tletter<<endl;
<<:i:"<<iletter<<endl;
<<"f:"<<fletter<<endl;
<<"u:"<<wletter<<endl
<<"l:"<<lletter<<endl;
getch();
return 0;
}

is my program right?if not,can u help me whats the reason why and what the code should be/
thank you very much

Unit
03-10-2005, 03:11 AM
Hmm.. why dont you explain your program to us? Tell us how your program does what your assignment needs.

Trust me, it will help you find out what is wrong with your program. Once you find what is wrong, we can help you fix it.

Use code tags around your code so that indentation is preserved. You can use comments to explain what you are doing at each line of your code.

psyche08
03-11-2005, 02:10 AM
the output of the program must
h=1
e=1
l=2
o=1
hello...it output how many times the letter appear..

Unit
03-11-2005, 02:33 AM
Hmm, have you read what I asked for? I will try and help you regardless. All I can say is show some motivation :). We are not here to do your homework for you. We are here to help you understand if you are willing.


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
int main()
{
//What are these variables doing? Didn't your question ask you to use arrays?
int bletter=0, eletter=0, aletter=0, uletter=0,tletter=0,iletter=0fletter=0, wletter=0,lletter=0,wdletter=0,notmatch=0;
char a;

clrscr();
cout<<"enter sentence:";
cin>>a;// you are reading one char. try reading a char array.
if(wdletter % 12 ==0)// What does this do? wdletter is initialized to 0!
cout<<endl;
for(a=0;a<buf.size();a++)//What is buf? Where did you read buf? using a as index?
{
switch(buf[a])
{
case'b':
++aletter;// using aletter variable when counting for b? Also, see above comment about using arrays for this. Ignoring other errors below. Fixing these would get you a long way.
break;
case'e':
++eletter;
break;
case'a':
++aletter;
break;
case'u':
++uletter;
break;
case't':
++tletter;
break;
case'i':
++iletter;
break;
case'f':
++fletter;
break;
case'w':
++wletter;
break;
case'l':
++lletter;
break;
default:
++notmatch;
break;
}
}
cout<<"\n\n";
<<"b:"<<bletter<<endl;
<<"e:"<<eletter<<endl;
<<"a:"<<aletter<<endl;
<<"u:"<<uletter<<endl;
<<"t:"<<tletter<<endl;
<<:i:"<<iletter<<endl;
<<"f:"<<fletter<<endl;
<<"u:"<<wletter<<endl
<<"l:"<<lletter<<endl;
getch();
return 0;
}