well, you may want to start with actually opening and closing the files... for example, your code just asks the user for the filename, and if it gets a valid one, does nothing with it. The only time it does anything useful is when they give you a bad filename.
Code:
#include <iostream>
#include <fstream>
#include <string>
std::string checkname(std::string filetype);
int main()
{
std::string filename(checkname("input"));
//now you actually have a valid filename
std::fstream file(filename.c_str(),std::ios::in);
/*
* now you read in from the file and put the main part of your program
* right here.
*/
file.close();
return 0;
}/*
* this function asks the user for input using the standard console input, and
* it keeps going through an internal loop until the user gives up a name of a
* valid (existing) file. Note that this function checks only for files that
* exist and can be read from. It does not check to see if a file can be
* created with a certain filename.
*/
std::string checkname(std::string filetype)
{
std::string filename;
std::fstream file;
do
{
/*
* clear the file flags, in case they entered a wrong input
* on the last iteration of the loop. If this is the first
* run of this loop, this line is just a waste of code.
*/
file.clear();
/*
* ask for and recieve a filename. Wether it's a valid file is
* open to scrutiny later on
*/
std::cout<<"Enter the "<<filetype<<" file name: ";
getline(std::cin,filename,'\n');
/*
* now we're testing to see wether or not it's a valid file.
* If the file doesn't exist, it's going to run the loop again.
* if the file does exist, it's going to exit the loop.
*/
file.open(filename.c_str(),std::ios::in);
if(!file)
{
std::cout<<"File doesn't exist - try again\n";
}
}
while(!file);
/*
* here we're closing the file that we just opened and we're returning
* the name of that file.
*/
file.close();
return filename;
}
as for the rest, I'd create two arrays - one for the first six numbers, and another for the second six. for the first six, it really doesn't matter what kind of sorting algorithm you use because there's only six of them, but for help with searching algorithms, a simple search will turn up a great wikipedia page: http://en.wikipedia.org/wiki/Sort_algorithm