padraga 0 Newbie Poster

Hi, I am quite new to C++,
Currently, I'm learning how to do a problem which will take a text file of thousand most common words in the english dicatonary with another text file. After finding how many words are in said text file show the percentage of which are in that file and percentage of which that are not. I'm not too sure where to put bits of code and the algothrims and math are wrong. Any tips/help is greatly accperiated.
#include <iostream>
#include <string>#include <fstream>
std::string mostCommonWords;
int commonWords;int totalWords;
`int totalWordsIn1000MostCommon;

`using namespace std;

int main(){
cout<<"1000 Most Common Words"<<endl;
string fileName;

cout<<"Please enter for the path for the file type"<<endl; 
cin>> fileName; 

ifstream infile; 
ofstream outfile; 

infile.open(fileName.c_str());
outfile.open("Users/Matt/Desktop/1000commonwords.txt"); 

if(infile.good() && outfile.good())
{
    //save 1000 common words to a string 

    for (int i=0; i<1000; i++) 
    {
        totalWordsIn1000MostCommon++; 
        break; 
    }

    while (infile.good()) 
    {
        //work on later
    }
}

else 
{
    cout<< "The file path was not found."<<endl; 
    return 0; 
}



cout<<"Enter in file to check with 1000 most common words"<<endl; 
string fileName2; 
cin>> fileName2; 

ifstream infile2; 
ofstream outfile2; 

infile.open(fileName2.c_str()); 
outfile.open("UserChoice"); 

if (infile.good() && outfile.good()) 
{
    //search thourgh file for commonwords 

    while (infile.good()) 
    {
    //work/search words for all commonwords 
    //once word is found search add to 
    }
}
//Once have all the words found in a file, take that and use the number found and not found and convert it to percentages. 

int start = 0; 
int end = 999; 
int middle; 
int SearchWord; 

while (end != start ) 
{
  //500       999    500 
    middle= (start + end)/2; 

    if (commonWords[middle] == SearchWord)
    {
        //count
        break;
    }
    `else if (commonWords[middle] < SearchWord)
    {
        start = middle; 
    }
    else
    {
        end=middle; 
    }
}

`}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.