1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void personCreator();
void extraInfo();
int main()
{
for (;;)
{
system("cls");
personCreator();
cout << "Press Enter to continue" << endl;
cin.get();
}
}
void personCreator()
{
string firstname, lastname, birthmonth, birthyear, date, extraInfo;
cout << "Whats your firstname? "; getline(cin, firstname);
cout << "Whats your lastname? "; getline(cin, lastname);
cout << "Whats your birth year? "; getline(cin, birthyear);
cout << "Whats your birth month? "; getline(cin, birthmonth);
cout << "Whats your birth date? "; getline(cin, date);
cout << "Got anything else to say about yourself?" << endl;
cout << "y for yes, n for no." << endl;
char response;
cin >> response;
switch (response)
{
case 'y':
{
fstream moreInfo(firstname + "_" + lastname + ".txt", std::fstream::out || std::fstream::app);
if (moreInfo.is_open())
{
system("cls");
cout << "Type in your extra info";
cin, extraInfo;
moreInfo << extraInfo << endl;
}
else
{
cout << "error" << endl;
}
}
case 'n':
break;
default:
cout << "Invalid choice" << endl;
}
ifstream reader(firstname + "_" + lastname + ".txt");
if (reader.is_open())
{
system("cls");
reader >> firstname >> lastname;
int agey = 2015 - atoi(birthyear.c_str());
cout << "Welcome back " << firstname << " " << lastname << " who is " << agey << " years of age." << endl;
}
else
{
system("cls");
cout << "Success, thank you for registering with us." << endl;
}
ofstream myfile;
myfile.open(firstname + "_" + lastname + ".txt");
if (myfile.is_open())
{
myfile << firstname << " " << lastname << endl;
myfile << birthyear << endl;
myfile << birthmonth << endl;
myfile << date;
myfile.close();
}
else
{
system("cls");
cout << "Error" << endl;
}
}
|