Guest User

Untitled

a guest
Jul 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. fstream records;
  12. records.open("donation_total.txt", ios_base::in | ios_base::out | ios_base::app);
  13. if (records.is_open())
  14. {
  15. cout << "The record file is open!" << endl;
  16. string line;
  17. while (!records.eof())
  18. {
  19. getline(records, line);
  20. }
  21. int total = stoi(line);
  22. cout << "Total donation is: "<<total << endl;
  23. cout << "Is there any new record?" << endl;
  24. string str,newname;
  25. stringstream field;
  26. string name;
  27. int donation;
  28. getline(cin , str);
  29. while (str=="Yes" | str=="yes")
  30. {
  31. cout << "Enter name and donation value: ";
  32. getline(cin, newname);
  33. field.str(newname);
  34. field >> name >> donation;
  35. total += donation;
  36. field.clear();
  37. cout << name << " donates " << donation << "$" << endl;
  38. cout << "Total donation is: " << total << endl;
  39. records << endl << total;
  40. cout << "Is there any new record?" << endl;
  41. getline(cin, str);
  42. }
  43. }
  44. else
  45. {
  46. cerr << "Could not find the file!" << endl;
  47. }
  48. records.close();
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment