Click to See Complete Forum and Search --> : C++ Question


teh supar faggort1
05-05-2001, 03:23 AM
Well... I have a question about a program I am messing with... I realize this is not a Linux question but I figured you all are much more knowledgable than many... So... Here's my problem. Almost all of it works, but then there is one section of code that doesn't... Can someone give me a hand? Thanks...

Here's the code:
===========================
#include "UTILITY2.inc"
#include "APVECTOR.H"

typedef apvector <char> ListType;

void EnterList(ListType &List);
void DisplayAll(ListType List);
void DisplayVowels(ListType List);
void DisplayConsonants(ListType List);

void main()
{
OutputSelection();
// Heading H("29","MM-DD-YY","100","RANDOM LETTERS");
Execution();
ListType List;
do
{
EnterList(List);
DisplayAll(List);
DisplayVowels(List);
DisplayConsonants(List);
}
while (NotFinished());
Terminate();
}


void EnterList(ListType &List)
{
int Length,K = 0;
Skip(4);
Title("Function Random Letter List");
Skip(2);

cout<<"How many letters will be generated ---> ";
cin>>Length;
List.resize(Length);

for(K=0; K < Length;K++)
{
List[K] = random(25)+65;
}
}

void DisplayAll(ListType List)
{
Skip(4);
Title("Display all Letters");
Skip(2);

int K = 0;
int Length = List.length();
for (K = 0; K < Length; K++)
{
cout << List[K] <<" ";
}
getch();
}

void DisplayVowels(ListType List)
{
int K = 0;
int Length = List.length();

Skip(4);
Title("Display of Vowel Letters");
Skip(2);

for (K = 0; K < Length; K++)
{
switch(List[K])
{
case 'A':
cout<<List[K]<<" ";
break;
case 'E':
cout<<List[K]<<" ";
break;
case 'I':
cout<<List[K]<<" ";
break;
case 'O':
cout<<List[K]<<" ";
break;
case 'U':
cout<<List[K]<<" ";
break;
}
}
getch();
}

void DisplayConsonants(ListType List)
{
int K = 0;
int Length = List.length();
bool Vowel = false;

Skip(4);
Title("Display of Consonant Letters");
Skip(2);

for (K=0; K < Length; K++)
{
Vowel = false;
switch(List[K])
{
case 'A':
Vowel = true; break;
case 'E':
Vowel = true; break;
case 'I':
Vowel = true; break;
case 'O':
Vowel = true; break;
case 'U':
Vowel = true; break;

if(Vowel == false)
cout<<List[K]<<" ";
}
}
}

===================
DisplayConsonants() does not work correctly... I am guessing it is some logic problem, but I have been staring at it for the last half hour and can't figure it out... Thanks for the help!

Tyr-7BE
05-05-2001, 03:29 AM
I recommend the programming forum...they specialize in this sort of thing.

Tyr-7BE
05-05-2001, 03:35 AM
Other than that, what happens when you call DisplayConsonants? Does it have an output but it counts vowels?

655321
05-05-2001, 03:51 AM
It's bad programming style to have everything lined up on the left like that.... You should indent... makes it easier to find things and get your bearings :D

So, yeah, what happens when you call it? Or doesn't it compile? What compiler errors do you get, what lines... or if it compiles, what happens? segmentation fault? or what? details, we need details.

teh supar faggort1
05-05-2001, 08:06 AM
It is indented on my .cpp file, but when I copied and pasted to here it got rid of the indentations... :-(

When it gets to the DisplayConsonants() it runs Title("whatever") and then it just ends the program... I don't know what is wrong with the case(List[K]) switch thing... Should work, it seemms to me... I will post it in the programming folder...

Thanks...

655321
05-05-2001, 10:04 AM
Originally posted by l33tb0y:
<STRONG>It is indented on my .cpp file, but when I copied and pasted to here it got rid of the indentations... :-(

When it gets to the DisplayConsonants() it runs Title("whatever") and then it just ends the program... I don't know what is wrong with the case(List[K]) switch thing... Should work, it seemms to me... I will post it in the programming folder...

Thanks...</STRONG>

Well, maybe your length function doesn't work right and its setting the length equal to zero. If that was the case, then the loop would never run... I dunno.... you should put test cout s all over the place to figure out exactly where it is going wrong.

[ 05 May 2001: Message edited by: 655321 ]

teh supar faggort1
05-05-2001, 10:17 AM
Oh... Duh... I get it... I left the cout statement inside the case(List[K]) thing... so of course it was not getting run... Stupid stupid me... but that's what learning is all about.. Anyways.. thanks for the help everyone...

binaryDigit
05-05-2001, 11:34 AM
next time you have a programming question put it in the programming forum.
(yeah i know someone already said that but....)
and when you post code use the code tags.

so that
your indentations
don't get messed up
and we can read
your code.