Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /*
  2. Arifur Rahman
  3. CS 136
  4. MELISSA LYNCH
  5. LAB 3A
  6. */
  7. #include <iostream>
  8. #include <fstream>
  9. #include <cstdlib>
  10. #include <climits>
  11. #include <string>
  12. using namespace std;
  13. int main(){
  14.  
  15. string date;
  16. double min = 10000;
  17. double max = 0;
  18. double eastSt,eastEl,westSt,westEl;
  19.  
  20. ifstream fin("Current_Reservoir_Levels.tsv");
  21. if (fin.fail()) {
  22. cerr << "File cannot be opened for reading." << endl;
  23. exit(1); // exit if failed to open the file
  24. }
  25. string junk; // new string variable
  26. getline(fin, junk); // read one line from the file
  27.  
  28. while(fin >> date >> eastSt >> eastEl >> westSt >> westEl) {
  29. // this loop reads the file line-by-line
  30. // extracting 5 values on each iteration
  31.  
  32. fin.ignore(INT_MAX, '\n'); //skips to the end of line,
  33. //ignoring the remaining columns
  34.  
  35. // for example, to print the date and East basin storage:
  36. if (max < eastSt)
  37. {
  38. max = eastSt;
  39. }
  40. else if (min > eastSt)
  41. {
  42. min = eastSt;
  43. }
  44. }
  45. cout << "minimun storage in East basin: " << min << "billion gallons" << endl;
  46. cout << "Maximum storage in East basin: " << max << "billion gallons" << endl;
  47. fin.close();
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement