Howdy all,
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.
Code:#include <string>
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string winner;
int salesmanId;
int salesmanNumber;
string winningMessage;
string filename;
ifstream inData;
ofstream outData;
cout<<"Please enter the name of the data file: ";
getline(cin,filename);
inData.open("salesday.dat");
cout<<setw(25)<<"Salesman Contest"<<endl;
cout<<endl;
cout<<setw(25)<<"October 2003"<<endl;
cout<<endl;
cout<<setw(15)<<"And the winner is: "<<endl;
cout<<endl;
cout<<"Amount of sales: "<<endl;
cout<<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 :confused: