Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int main()
- {
- fstream records;
- records.open("donation_total.txt", ios_base::in | ios_base::out | ios_base::app);
- if (records.is_open())
- {
- cout << "The record file is open!" << endl;
- string line;
- while (!records.eof())
- {
- getline(records, line);
- }
- int total = stoi(line);
- cout << "Total donation is: "<<total << endl;
- cout << "Is there any new record?" << endl;
- string str,newname;
- stringstream field;
- string name;
- int donation;
- getline(cin , str);
- while (str=="Yes" | str=="yes")
- {
- cout << "Enter name and donation value: ";
- getline(cin, newname);
- field.str(newname);
- field >> name >> donation;
- total += donation;
- field.clear();
- cout << name << " donates " << donation << "$" << endl;
- cout << "Total donation is: " << total << endl;
- records << endl << total;
- cout << "Is there any new record?" << endl;
- getline(cin, str);
- }
- }
- else
- {
- cerr << "Could not find the file!" << endl;
- }
- records.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment