473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[| -- C++ Help Please: Counting Vowels in a Given Text -- |]

Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u)

For my test run I have to use "unquestionably", but I can't anything to work. Here's what I have so far.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. void stringout();
  8. string input;
  9.  
  10. int main()
  11. {
  12.  
  13.     cout << "Input a string of characters: " ;
  14.     cin >> input;
  15.     cout << "You entered: " << input << endl;
  16.  
  17.     stringout();
  18.  
  19.  
  20.     return 0;
  21. }
  22.  
  23. void stringout()
  24. {
  25.     char ch;
  26.     int vowel=0, consonant=0;
  27.     int length = input.length();
  28.  
  29.     for (int i = 0; i < length; i++)
  30.     {
  31.         if ((ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u') ||
  32.             (ch == 'A') || (ch == 'E') || (ch == 'I') || (ch == 'O') || (ch == 'U'))
  33.             ++vowel;
  34.     else
  35.         ++consonant;
  36.     }
  37.  
  38.  
  39.     cout << "This has " << input.length() << " characters, " <<endl;
  40. }
It keeps telling me to input a string of characters, but even when do put in "unquestionably" into the put space it doesn't help. Can anyone give me a hand, please?
Oct 29 '08 #1
6 4259
donbock
2,426 Expert 2GB
Hi I'm supposed to be writing a program that counts in a given text, the words that contain at least three different vowels (a,e,i,o,u)

For my test run I have to use "unquestionably", but I can't anything to work.

It keeps telling me to input a string of characters, but even when do put in "unquestionably" into the put space it doesn't help. Can anyone give me a hand, please?
Are you saying that all your program does is continuously print the following?
Input a string of characters: unquestionably
You entered: unquestionably
Input a string of characters: unquestionably
You entered: unquestionably
Input a string of characters: unquestionably
You entered: unquestionably
...


Boy, I sure don't see why it would do that. Are you sure these are the symptoms? Can you provide a copy of what you see on your terminal?
Oct 29 '08 #2
Yea sure.

[IMG]

[/IMG]
Oct 29 '08 #3
boxfish
469 Expert 256MB
Just type in a string of characters when it says to. It should work fine. Except that if you are running this program from windows explorer or some such, it will probably close as soon as you press enter. If this happens, you can put a line of code at the end of your program that waits for some more input, but I've heard this is a bad thing to do. Two cin.get()s should work, but am I right that there is a good reason not to do this?
Hope this helps.
Edit:
May I suggest making input an argument to stringout, instead of a global variable? Global variables are definitely a bad thing.
Oct 29 '08 #4
AmeL
15
Yep you can prompt a user to press any key before exiting; yet you can launch your command prompt and execute your .exe to see what is displayed.
However ( this is not what you asked for ), I found that your code does not really count the number of vowels or consonant of the inputted string from users. It had better that you redesign your code again to make it work as what is required.
Oct 30 '08 #5
donbock
2,426 Expert 2GB
It sounds like you're uncertain of the purpose of the I/O commands between lines 13 and 15.
What do you think those lines are trying to accomplish?
Oct 30 '08 #6
donbock
2,426 Expert 2GB
In function stringout, what is the purpose of variable ch?
What is its value?
Oct 30 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Srinath Avadhanula | last post by:
Hello, I am wondering if there is a way of counting graphemes (or glyphs) in python. For example, in the following string: u'\u0915\u093e\u0915' ( or equivalently, u"\N{DEVANAGARI LETTER...
8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
6
by: edwardfredriks | last post by:
I'm looking for a script that, instead of counting down, can "count up" from a given date. So the output should be something like "(xx) days since (date/event)" or "(date/event) was (xx) days ago"....
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
4
by: bigbagy | last post by:
Notes The programs will be compiled and tested on the machine which runs the Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used. A significant amount coding is...
5
by: ivalki | last post by:
Hi How do i use the functions found in string.h to check if a letter is vowel and a consonant ? I have this code : ......... const char vowel="aeiou"; const char...
1
by: powerej | last post by:
I have gotten the part of counting how many words are in the string, but the vowels just seem alien to me. Ive tried so many things but never close to a correct answer. I know I need to use...
2
by: Geneses | last post by:
Hi! I'm using Eclipse as an IDE, I need to code a program where users enter a string and it computes the count for each vowel, and how many words are in the string. Users can do as many strings as...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.