Facebook
From Innocent Dove, 4 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 141
  1. #include <iostream>
  2. #include <fstream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. void Clean() {
  10.     system("cls");
  11.     cout << "\t\t--- WELCOME TO OUR DATABASE! ---\n\n";
  12. }
  13.  
  14. bool AddUser() {
  15.     fstream file;
  16.     string name, surname, age;
  17.     // Clean();
  18.     cout << "User name:\n";
  19.     getline(cin, name);
  20.     // Clean();
  21.     cout << "User surname:\n";
  22.     getline(cin, surname);
  23.     // Clean();
  24.     cout << "User age:\n";
  25.     getline(cin, age);
  26.     file.open("data.txt", ios::out | ios::app);
  27.     if (!file.good()) {
  28.         cout << "Error while opening the file! Press the button to end the program...";
  29.         getch();
  30.     }
  31.     else {
  32.         file << name << endl;
  33.         file << surname << endl;
  34.         file << age << endl;
  35.         file.close();
  36.         string answer;
  37.         cout << "Add another? (y/n)\n";
  38.         cin >> answer;
  39.         if (answer == "y") {
  40.             return false;
  41.         }
  42.         else if (answer == "n") {
  43.             return true;
  44.         }
  45.         else {
  46.             cout << "You could write again?\n";
  47.         }
  48.     }
  49.     return true;
  50. }
  51.  
  52. int main() {
  53.     bool complete;
  54.     do {
  55.         complete = AddUser();
  56.     } while(complete == false);
  57.     return 0;
  58. }