Advertisement
andrefecto

Testing

Dec 1st, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. // basic file operations
  2. #include <iostream>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int main () {
  7.   ifstream infile;
  8.   string line;
  9.   line = "";
  10.   string name;
  11.   name = "";
  12.   double rate;
  13.   rate = 0.0;
  14.   double monday;
  15.   monday = 0.0;
  16.   double tuesday;
  17.   tuesday = 0.0;
  18.   double wed;
  19.   wed = 0.0;
  20.   double thursday;
  21.   thursday = 0.0;
  22.   double friday;
  23.   friday = 0.0;
  24.   double total;
  25.   total = 0.0;
  26.  
  27.         while (true)
  28.             {
  29.                 string infilename;
  30.                 cout << "Please Enter the name of the file to be opened: ";
  31.                 getline( cin, infilename);
  32.                 infile.open( infilename.c_str() );
  33.                 if(infile)break;
  34.                 cout << "Invalid File. Please, try again."<< flush;
  35.             }
  36.             //while (!infile.eof() )
  37.                 {
  38.                     int i;
  39.                     for(i = 0; i < 1; i++)
  40.                         {
  41.                             getline (infile, line);
  42.                             name = line;
  43.                             cout << "name: " << name << endl;
  44.                             infile >> rate;
  45.                             cout <<"rate: " << rate << endl;
  46.                             infile >> monday;
  47.                             cout << "M: " << monday << endl;
  48.                             infile >> tuesday;
  49.                             cout << "T: " << tuesday << endl;
  50.                             infile >> wed;
  51.                             cout << "W: " << wed << endl;
  52.                             infile >> thursday;
  53.                             cout << "R: " << thursday << endl;
  54.                             infile >> friday;
  55.                             cout << "F: " << friday << endl;
  56.                             total = monday+tuesday+wed+thursday+friday;
  57.                             cout << "Total: " << total << endl;
  58.                         }
  59.                 //}
  60.   infile.close();
  61.   return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement