The task is to put text in ab Edit box & then to iterate over it. The result should be in a block graph. If there is a vowel =="A" then block one should rise, if =="B" then block two should rise to represent it.

I can make this work for the first letter in the edit box with the following code:

/* {
  int Index;
    Index=1;

    for(Index=1;Index<=5;Index++)
    {

       if(Edit1->Text=="A")
       {
       Shape1->Height= (Shape1->Height+5);
       Shape1->Top = Shape1->Top -5;
       }
          if(Edit1->Text=="E")
          {
           Shape2->Height= (Shape2->Height+5);
           Shape2->Top = Shape2->Top -5;
          }
              if(Edit1->Text=="I")
              {
              Shape3->Height= (Shape3->Height+5);
              Shape3->Top = Shape3->Top -5;
              }
                  if(Edit1->Text=="O")
                  {
                  Shape4->Height= (Shape4->Height+5);
                  Shape4->Top = Shape4->Top -5;
                  }
                     if(Edit1->Text=="U")
                     {
                     Shape5->Height= (Shape5->Height+5);
                     Shape5->Top = Shape5->Top -5;
                     }
     }*/

BUT this only works when the letter is at Index=1. I need to scan a sentence so that the result of the graph shows how many A's how many E's how many I's how many O's how many U's.

How do I get it to read over the text & not just the first letter?

Presumably Edit1->Text is a string of some type. Assuming this is a Windows based program, then it's probably a C style string. If that assumption is correct then each letter in the string can be accessed by using the [] operator, like this:

Edit1->Text[x];

where x ranges from 0 to strlen(Edit1->Text) - 1.

If Edit1->Text is some form of a string other than a C style string, then some other form of access may be necessary.

NB: you might need to copy Edit1->Text to another string like this:
char input[256];
strcpy(input, Edit1->Text);

and then iterate through input if this

Edit1->Text[x];

doesn't work.

Hi there,

Its C++, using Boreland 5 as a compiler, so its really visual C++, but using C++ as basis. I'm afraid this didn't work, do you have any other ideas.

The problem is just to iterate over a line of text & then show the vowels in a bar chart.

Any suggestions would be greatly appreciated.

Thanks

jenco

Presumably Edit1->Text is a string of some type. Assuming this is a Windows based program, then it's probably a C style string. If that assumption is correct then each letter in the string can be accessed by using the [] operator, like this:

Edit1->Text[x];

where x ranges from 0 to strlen(Edit1->Text) - 1.

If Edit1->Text is some form of a string other than a C style string, then some other form of access may be necessary.

NB: you might need to copy Edit1->Text to another string like this:
char input[256];
strcpy(input, Edit1->Text);

and then iterate through input if this

Edit1->Text[x];

doesn't work.

Edit->Text should be a word or a phrase, say you entered ther phrase--three blind mice. Again that word/phrase should be a string of some type, in Borland it might be called a TString or some such. Whatever. That string type should have an overloaded [] operator associated with it to allow you to access each letter in the word or phrase (and it should have a method for you to extract the embedded C style string if you wish, maybe c_str() or some such, if you really wanted to). With that you can iterate over each letter in the input one by one. When refering to a hard coded letter in C/C++ you use single quotes, like this, 'A', rather than double quotes like this, "A", which are used to denote a string called a literal string (it isn't quite the same thing as a routine C style string, but it's close). Therefore, I'd:

1) Find the length of the string in Edit1 using whatever method you have available.
2) Convert the string into all caps or all lower case letters so I didn't have to worry about 'A' vs 'a', etc.
3) Create a container to hold the number of A, E, I, O and Us found in the string
4) Iterate over the entire string incrementing the appropriate counter in the container based on the letter found.
5) Display the results graphically by iterating over the container of counters representing the number of A, E, I, O and Us.

So maybe something like this:

//copy TString or whatever into a C style string 
char input[256];
strcpy(input, Edit1->Text.c_str());
//find it's length
int len = strlen(input);
//convert it to all upper case letters
for(int  j = 0; j < len; ++j)
  input[j] = toupper(input[j]);

//declare container of counters and initialize to zero
int counters[5] = 0;

//iterate over input finding vowels
for(int j = 0; j < len; ++j)
{
  //I'd use a switch statement instead of a series of if statements
  switch(input[j])
  {
     case 'A': //notice single quotes, not double
       counter[0]++;
       break;
     case 'E':
       counter[1]++;
       break;
     //etc
   }
}

//use a loop and the graphical interface to create pretty bars representing number of A, E, I, O and Us found in input which in turn was Edit1->Text.

I don't like the idea of having to learn the basic principles of looping, usage of the [] operator to access individual char of a string, and retrieval of and manipulation of data from edit boxes in addition and creation of colored bars to display results. But if that's what you have to do, then so be it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.