•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,571 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,617 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 490 | Replies: 5
![]() |
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
hi i am writing a program that counts words containing at least 3 different vowels using functions and also input files.i am confused here and don't know what to do.in this program i am to write another function that will output either 1 or 0 when a character is a vowel or not.please help me . this is where i've gotten so far
cplusplus Syntax (Toggle Plain Text)
#include<iostream> #include<fstream> #include<string> using namespace std; void vowel(string, string, string) int main() { string line,L1,L2,L3; string filename = "vowel.txt"; ifstream inFile; inFile.open("vowel.txt" , ios::in); if ( !inFile.fail()) { cout<<"\nThe file has been succesfully opened\n"; } while(getline(inFile,line)) cout<<line<<endl; vowel(L1, L2, L3); return 0; } void vowel(string L1, string L2, string L3) { string word; int count
Last edited by Ancient Dragon : Oct 27th, 2007 at 9:49 pm. Reason: add code tags
•
•
Join Date: Jul 2005
Posts: 1,288
Reputation:
Rep Power: 9
Solved Threads: 175
Will the file be one word per line or do you have to parse the line into individual words.
Once you have a single word I'd send it to vowel(). I don't know why you would want to send three strings to vowel(). You don't really need the string word in vowel(). I'd initialize count to zero before I tried to use it. I'd create a string containing all the vowels I'm looking for. Then I'd use a nest loop to compare each letter of the word passed to vowel with each letter in the string of vowels.
PS: Please use code tags when posting code to this board.
Once you have a single word I'd send it to vowel(). I don't know why you would want to send three strings to vowel(). You don't really need the string word in vowel(). I'd initialize count to zero before I tried to use it. I'd create a string containing all the vowels I'm looking for. Then I'd use a nest loop to compare each letter of the word passed to vowel with each letter in the string of vowels.
PS: Please use code tags when posting code to this board.
Last edited by Lerner : Oct 27th, 2007 at 8:54 pm.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
You need to put a return after line 18 is executed because there is no point contuining that function if it fails to open the file.
Last edited by Ancient Dragon : Oct 27th, 2007 at 9:55 pm.
•
•
Join Date: Jul 2007
Location: Toronto, Canada
Posts: 20
Reputation:
Rep Power: 2
Solved Threads: 1
I have just read the whole thing and I am confused as to what do you have to do here. And I am getting sys. reqs from some crazy manages for a living. So you got to count unique vowels? Can we get an example of the text file? Ancient Dragon is right, got to exit if file is not opened properly, I guess you guys did not study exceptions yet, simple return would do.
Keep in mind, your L1, L2 and L3 are not innitialized and are passed into a your mistery function, that is no good.
While not clearly understanding what do you have to do here, here is my suggestion on how to make at least what you wrote workable:
Keep in mind, your L1, L2 and L3 are not innitialized and are passed into a your mistery function, that is no good.
While not clearly understanding what do you have to do here, here is my suggestion on how to make at least what you wrote workable:
int main(){
string line,L1,L2,L3;
string filename = "vowel.txt";
ifstream inFile;
inFile.open("vowel.txt" , ios::in);
if ( inFile.fail())
{
cout<<"\nThe file is not there or some other terrible thing had happened in the process
soon we will learn about exceptions and this type of deal would be much easier.\n";
//exiting with -1 would at least indicate that something bad had happened
return -1;
}
cout<<"We are cooking with gas now"<<endl;
//i am not sure on reading a line part, have not touched c++ since school
while(getline(inFile,line))
{
cout<<line<<endl;
//like I mentioned above, your L* are not innitialized
vowel(L1, L2, L3);
return 0;
} ===========================
can you repeat the part of the stuff where you said all about the things?
can you repeat the part of the stuff where you said all about the things?
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- confused about SE + SEO. (Search Engine Optimization)
- Confused about SATA RAID (Storage)
- Confused about loops and switch (Java)
- Confused writing a Java Class (Java)
- confused about shell sort ... (C)
- confused how to begin this program (C++)
- Need help With this C++ Program..Confused.. (C++)
- ftp client issues...im so confused...plz help!!! (Windows Software)
Other Threads in the C++ Forum
- Previous Thread: Regex
- Next Thread: New 2 C++ please help



Linear Mode