Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,080 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




help with this c++ home work

 
Reply to this topicStart new topic

help with this c++ home work, programmin

obrianto
21 Apr, 2008 - 07:41 AM
Post #1

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 6


My Contributions
Some languages use many more vowels than others. For example, in Hawaiian “Puu Kaa Lani” has
6 vowels and 4 consonants, while the name of a former Austrian minister: “Gschwendl” has just one
vowel in 8 consonants. In the above examples, the ratio for Hawaiian is 6/4 and for Austrian 1/8.

Write a program that inputs a line of text, calculates the ratio of vowels to consonants and prints that line
with the corresponding ratio. Numbers, spaces and punctuation do not count, for example May 26, 1999
has a ratio of 1 /2. The program should repeat the process until the user enters an empty line. At the end,
it should write the lines with the highest and lowest ratio. It should count only letters, disregarding any
other character. Note: A, a, E, e, I, I, O, o, U, u are vowels and other letters are consonants. (7.5 points)
Sample Input and Output:
Please enter a line of text >
Puu Kaa Lani
“Puu Kaa Lani” vowel to consonant ratio is: 6/4
Please enter a line of text >
Kellogg Competition
“Kellogg Competition ” vowel to consonant ratio is: 7/11
Please enter a line of text >
Mercy College
“Mercy College” ratio vowel to consonant is: 4/8
Please enter a line of text >

The line with the lowest ratio is:
“Mercy College” ratio vowel to consonant is: 0.5

The line with the highest ratio is:
“Puu Kaa Lani” vowel to consonant ratio: 1.5


User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Help With This C++ Home Work
21 Apr, 2008 - 08:07 AM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
hmm you really need to post your code before we can do anything, but here's a little help:
Try writing a little pseudocode first - this is basically written in your own spoken language on what the program needs to do. So think about this:
  1. What variables do you need? a string for input, an int to count consonants and an int to count vowels
  2. The program needs to get a string from the user
  3. It then needs to loop through the string and if the current character is a consonant, add 1 to the value of consonantTotal, otherwise add 1 to the value of vowelTotal.
  4. Output the counts in a ratio format (vowelTotal:consonantTotal)
  5. Ask the user if they want to process another string. If so, start over, otherwise exit the program.

The last one would probably just be extra credit, because judging by your example output, it would just start over anyway and the user would just have to press the X to exit

Another way you could do it is if the user just inputs X to exit, instead of asking again.

Hope this helps smile.gif

This post has been edited by gabehabe: 21 Apr, 2008 - 08:09 AM
User is offlineProfile CardPM
+Quote Post

obrianto
RE: Help With This C++ Home Work
21 Apr, 2008 - 08:38 AM
Post #3

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 6


My Contributions
to be honest am really lost in that class and would really like to have just a starting code to build on i would appreciate the help. and thanks for replying so quickly.
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Help With This C++ Home Work
21 Apr, 2008 - 09:09 AM
Post #4

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,522



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Well, since you asked so nicely smile.gif lol

cpp

#include <iostream> //standard input/output

using namespace std; // standard namespace

int main ()
{
int consonantTotal = 0; // total number of consonants
int vowelTotal = 0; // total number of vowels

char input[256]; // the string that the user enters

cout << "Please enter a string> "; // prompt the user
gets(input); // gets the string from the user, gets() allows spaces

. . .
}


There's something to get you started. The next thing you need to think about is using a for loop, like so:
cpp
for (int i = 0; i < strlen(input); i++)
{
. . .
}


In that, you need to count the vowels and consonants using and if() else statement.

Finally, you would need to output the ratio.

HINT: If you want it to do this continuously, try putting all of that inside a while(true) loop - its an infinite loop smile.gif
User is offlineProfile CardPM
+Quote Post

obrianto
RE: Help With This C++ Home Work
21 Apr, 2008 - 10:50 AM
Post #5

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 6


My Contributions
thanks alot for your help. i wreally apreciate it. now i think i have an idea of the for loop
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 07:38PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month