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. -
#include <iostream>
-
#include <string>
-
#include <cstring>
-
-
using namespace std;
-
-
void stringout();
-
string input;
-
-
int main()
-
{
-
-
cout << "Input a string of characters: " ;
-
cin >> input;
-
cout << "You entered: " << input << endl;
-
-
stringout();
-
-
-
return 0;
-
}
-
-
void stringout()
-
{
-
char ch;
-
int vowel=0, consonant=0;
-
int length = input.length();
-
-
for (int i = 0; i < length; i++)
-
{
-
if ((ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u') ||
-
(ch == 'A') || (ch == 'E') || (ch == 'I') || (ch == 'O') || (ch == 'U'))
-
++vowel;
-
else
-
++consonant;
-
}
-
-
-
cout << "This has " << input.length() << " characters, " <<endl;
-
}
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?
6 4289 donbock 2,426
Recognized Expert Top Contributor
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?
Yea sure.
[IMG] ![](/images/imgserve.php?url=http://i231.photobucket.com/albums/ee44/HalfAmazin89/Cplusplus.jpg)
[/IMG]
boxfish 469
Recognized Expert Contributor
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.
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.
donbock 2,426
Recognized Expert Top Contributor
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?
donbock 2,426
Recognized Expert Top Contributor
In function stringout, what is the purpose of variable ch?
What is its value?
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 KA}\N{DEVANAGARI VOWEL SIGN AA}\N{DEVANAGARI LETTER KA}"
)
|
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 "char" with an ASCII code
in 0..127
I've searched the ANSI C++ standard, the internet and various text books,
but can't see how to workaround this one. I've tried wchar_t and wstring
without success.
But rather than spending lots of time on...
|
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".
Does anybody know where to find a script like that, or could someone
code one for me?
Thanks in advance.
Yours,
|
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 implement all three techniques as
programs. In these programs, as well as solving the problem, you will
also measure how long the program takes to run. The programs are worth
80% of the total mark. The final 20% of the marks are awarded for a...
|
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 needed for this assignment.
1.Counting Words in C++
Problem: Write an elegant C++ program to count the number of times each word occurs
in a file. A word is defined as a sequence of characters surrounded by whitespace. Case is
not important, so...
| |
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 consonant="bcdfghjklmnpqrstvwxyz";
|
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 charAt() and length() some nested loops with do while and for, but cant seem to get headed in the right direction. Also when i click the cancel button my program is suppose to end and tell you how many lines were entered, a count of vowels from all lines...
|
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 they want until they hit cancel. This is what I have so far:
import javax.swing.*;
public class Program
{ //Open Class
public static void main(String args)
{ //Open Main
String input, output; //Holds input and output.
int aCount = 0,...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |