I am having a bit a trouble understanding how file input and output works. I am working on a Lab for Intro to C++ and I need to work with input output and loops:
· Process input from 2 files: salesDay.dat and salesNight.txt
· Must allow the user to type the name for the input file so that the name can be stored in a variable. This allows you to process either file with no changes to your program.
· Will input 4 salesman from the day crew and 4 from the night crew
· Will use a counter and accumulator
· Will compute and print the average sales.
· Will print 2 salesman if there is a tie. (Check the sample screen). We will assume that no more than 2 salesman will ever have the same sales figure but 2 might.
· Will store the salesman's ID (a number) and his sales figure for printing later.
· Will use at least one switch statement.
· Format all output as closely as possible to the sample screens.
That's what I need to do. Now I have started writing the code but I am stuck at opening up the input files. This is what I have so far.
using namespace std;
cout<<"Please enter the name of the data file: ";
cout<<setw(15)<<"And the winner is: "<<endl;
cout<<"Amount of sales: "<<endl;
I don't want answers as I want to figure it out myself. But y question is is this correct for inputting a file? Does the input get stored in a variable? I am kinda looking for a pointer in the right direction. Again, I wanna figure this out but I'm a little cinfused with file input and output.
P.S. The tutorial wasn't much help