#include<iostream.h>
#include<stdlib.h>

const int MAXCHARS = 500;
char st_line[MAXCHARS];
char ch_option;
int i_va;
int i_ve;
int i_vi;
int i_vo;
int i_vu;
int i_word;
int i_count = 1;
int i_number = 0;
int i_vowel = 0;
char ch_char;


void getdata();
void vowels();
void words();
void putdata();

int main()
{
do{
getdata();
vowels();
words();
putdata();
}while(ch_option != 'y');
}

void getdata()
{
cout << "\nPlease enter line of text:\n";
cin.getline(st_line,MAXCHARS);
vowels();
}

void vowels()
{

while((ch_char = st_line[i_number++]) != '\0')
switch(ch_char)
{
case 'a': case 'A':
ch_char = i_va;
case 'e': case 'E':
ch_char = i_ve;
case 'i': case 'I':
ch_char = i_vi;
case 'o': case 'O':
ch_char = i_vo;
case 'u': case 'U':
ch_char = i_vu;
i_vowel++;
}
return;
}

void words()
{

if(st_line[i_word] == ' ' || st_line[i_word] == '\0')
i_count--;
while(st_line[i_word] != '\0')
{
if(st_line[i_word] == ' ' && (st_line[i_word + 1] != ' ' && st_line[i_word + 1
] != '\0'))
i_count++;
i_word++;
}
return;
}


void putdata()
{
cout << "\nInputted String";
cout << "\n\n*******************************";
cout << "\n\n " << st_line;
cout << "\n\nNumber of a's: " << i_va;
cout << "\nNumber of e's: " << i_ve;
cout << "\nNumber of i's: " << i_vi;
cout << "\nNumber of o's: " << i_vo;
cout << "\nNumber of u's: " << i_vu;
cout << "\nTotal Vowels: "<< i_vowel;
cout << "\n\nNumber of Words: " << i_word;
cout << "\n\n\nDo you want to exit (Y/N)? ";
cin.get(ch_option);
}
Wrong program this is the one that runs but it doesnt loop when i want it to and I wanna know how can I make it count the number of words that the user inputs


#include<iostream.h>
#include<stdlib.h>

const int MAXCHARS = 500;
char st_line[MAXCHARS];
char ch_option;
int i_va;
int i_ve;
int i_vi;
int i_vo;
int i_vu;
int i_number = 0;
int i_vowel = 0;
char ch_char;


void getdata();
void vowels();
void putdata();

void main()
{
while(ch_option != 'n')
   {
getdata();
vowels();
putdata();
   }
}

void getdata()
{
        cout << "\nPlease enter line of text:\n";
        cin.getline(st_line,MAXCHARS);
}

void vowels()
{
while((ch_char = st_line[i_number++]) != '\0')
switch(ch_char)
  {
        case 'a': case 'A':
          i_va++;
        break;
        case 'e': case 'E':
          i_ve++;
        break;
        case 'i': case 'I':
          i_vi++;
        break;
        case 'o': case 'O':
          i_vo++;
        break;
        case 'u': case 'U':
          i_vu++;
        break;
  }
        i_vowel = i_va + i_ve + i_vi + i_vo + i_vu;
}


void putdata()
{
        cout << "\nInputted String";
        cout << "\n\n*******************************";
        cout << "\n\n " << st_line;
        cout << "\n\nNumber of a's: " << i_va;
        cout << "\nNumber of e's: " << i_ve;
        cout << "\nNumber of i's: " << i_vi;
        cout << "\nNumber of o's: " << i_vo;
        cout << "\nNumber of u's: " << i_vu;
        cout << "\nTotal Vowels: "<< i_vowel;
        cout << "\n\nNumber of Words: ";
        cout << "\n\n\nDo you want to exit (Y/N)? ";
        cin.get(ch_option);
}
This article has been dead for over six months. Start a new discussion instead.