Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctype.h>
- #include <cmath>
- #include <fstream>
- #include <string>
- using namespace std;
- void login();
- void signup();
- int prompt();
- int filter(char command[]);
- int main()
- {
- switch ( prompt() )
- {
- case 1:
- login();
- break;
- case 2:
- signup();
- break;
- }
- }
- int prompt()
- {
- char command[12];
- cout << " _________________________________ " << endl;
- cout << "| |" << endl;
- cout << "| Welcome to our game! |" << endl;
- cout << "| ---------------------- |" << endl;
- cout << "| What would you like to do? |" << endl;
- cout << "| ---------------------- |" << endl;
- cout << "|_________________________________|" << endl;
- cout << endl;
- while (true)
- {
- cout << ">> ";
- cin >> command;
- cin.ignore(100, '\n');
- cout << endl;
- if (filter(command) == 0)
- {
- cout << "\nERROR: Command wasn't recognized. Try again?" << endl;
- continue;
- }
- else
- break;
- }
- return filter(command);
- }
- int filter(char command[])
- {
- if ( _stricmp("play",command) == 0 || _stricmp("start",command) == 0 || _stricmp("login",command) == 0)
- return 1;
- else if ( _stricmp("new",command) == 0 || _stricmp("create",command) == 0 || _stricmp("make",command) == 0 )
- return 2;
- else
- return 0;
- }
- void login()
- {
- // ...
- }
- void signup()
- {
- ofstream loginData("data.txt", ios::app);
- if (loginData.fail())
- {
- cout << "ERROR: Login data was not found." << endl;
- exit(-1);
- }
- string username, password;
- cout << "Desired Username: ";
- getline(cin, username);
- cout << "Desired Password: ";
- getline(cin, password);
- loginData << username << endl;
- loginData << password << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement