crazysaint Posted July 7, 2011 Share Posted July 7, 2011 Write an algorithim in pseudo code that will ask a user to input a sentence and that will return the number of vowels that are found in a sentense. i am a newbie to programming so all assistance will be highly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/241305-pseudo-code-assistance/ Share on other sites More sharing options...
trq Posted July 7, 2011 Share Posted July 7, 2011 We are not here to do peoples homework, where exactly are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/241305-pseudo-code-assistance/#findComment-1239498 Share on other sites More sharing options...
crazysaint Posted July 7, 2011 Author Share Posted July 7, 2011 this is what i have $vowels = array('a','e','i','o','u'); $string = 'An example string'; $length = strlen($string); $count = 0; for ($i = 0; $i !== $length; $i++ { if (array_search($length[$i], $vowels)) { $count++; } } echo 'There are (' . $count . ') vowels in the sentense(' . $string . ').'; Quote Link to comment https://forums.phpfreaks.com/topic/241305-pseudo-code-assistance/#findComment-1239501 Share on other sites More sharing options...
WebStyles Posted July 29, 2011 Share Posted July 29, 2011 since you tried (and almost had it) here's a similar way to do it: <?php $vowels = array('a','e','i','o','u'); $string = 'An example string'; // split string into array, make all lowercase (or I would have to add uppercase vowels to $vowels) $parts = str_split(strtolower($string)); $count = 0; foreach ($parts as $letter) { if (in_array($letter, $vowels)) $count++; } echo 'There are (' . $count . ') vowels in the sentence (' . $string . ').'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241305-pseudo-code-assistance/#findComment-1248975 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.