C++ Homework Solution Assistance

I am in a C++ class in college and we have to write a movie recommendation program. We have to open a text file and read data from it. Then sort the data and output it as a movie recommendation. The text file is titled movies.txt. The data in the text file looks like this:
24 8 2.78628
The first number is "movie1", the second number is "movie2" and the last number is "percent". I have to select the highest percent and output percent, movie1 and movie2. There are about 40 lines of data in the same format as above in the movies.txt file.

Here is my code snippet for what I am working with:

int userchoice, bestmovie, movie1, movie2;
double percent, bestpercent=0;
ifstream inFile;
ofstream outFile;

inFile.open("movies.txt");


while (inFile >> movie1 >> movie2 >> percent)

if ((userchoice == movie1) && (percent >= bestpercent))


inFile.close();

cout<<percent<<bestpercent<<endl<<bestmovie<<endl<<movie1<<endl<<movie2<<endl;
//cout <<setprecision (2)<< bestpercent << " % of people who liked movie # " << movie1;
//cout<< " also liked movie # " << movie2 << endl;

system ("pause");

return 0;
}


Here is what I do not know:
How do I get the data from the text file to store in a variable which I can output?
How to I sort my data so that the highest "percent" field and correlating movie numbers are selected and output. I am attempting to use my loops to select the data and validate but my output is always the same and clearly does not work. Any guidance would be much appreciated. Thanks!
I forgot to mention, I am using Visual Studio 2008 for this project. Thanks!
I'd use getline() to read in each line of the file then split the strings up into seperate variables myself.

You read the tutorial covering this sort of stuff on this site?
http://www.cplusplus.com/doc/tutorial/files/

atoi() can be used to turn a string into an integer which should make comparing percentages easy:
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/

Hope that helps in some form, fairly new myself but will check back later when I have more time.

(apologies if this is a bad bump)

first question, pretty simple actually, after inFile.open("movies.txt");

inFile >> movie1 >> movie2 >> percent;

or whatever variables you're trying to put it in, the line
while (inFile >> movie1 >> movie2 >> percent)
confuses me a bit.

i would answer the second question but i'm out of time for now, I'll help more later if i can.
I solved the program today. I will post the code to show the solution after next wednesday. I do not want to post it earlier out of respect and professional courtesy to the professor as it is not due until then. Essentially my major mistake was closing the .txt file inside the "while(inFile>>movie1>>movie2>>percent)" loop. This loop reads the file from beginning to end and assigns the values found in columns 1-3 to movie1, movie2, and movie3. Thank you all for your help and ideas on this project.
Topic archived. No new replies allowed.