我将简化我的问题...我将如何实现If / else语句或任何语句来获取用户从我的createaccount函数输入的数据并根据登录函数进行验证?如果登录名与文件" accounts.txt"中的内容不匹配,则无效并循环回主菜单功能。
using namespace std;
char mainMenu();
void createAccount();
void login();
char bankingMenu(); // Prototypes Declared Here
void deposit();
void withdraw();
void displayBalance();
void ShowTransHist(); // Gets transaction history from the file path string and display
int main()
{
char choice;
while (choice != 'q' || choice != 'Q')
{
choice = mainMenu();
if (choice == 'q' || choice == 'Q') break;
switch (choice)
{
case 'l':
case 'L':
login();
break;
case 'c':
case 'C':
createAccount();
break;
case 'v':
case 'V':
cout << "Thank you for using our bank and Future Computer Programmer ATM Machine! \nFor your continued support, we are offering 3% cash back on all debit purchases." << endl;
}
}
return 0;
}
char mainMenu() // Function to display the main menu, not banking menu
{
char choice;
cout << "Please select an option from the menu below:" << endl;
cout << "l -> Login" << endl;
cout << "c -> Create New Account" << endl;
cout << "v -> View Promotions" << endl;
cout << "q -> Quit" << endl;
cout << "Enter your choice: " << endl;
cin >> choice;
return choice;
}
void createAccount() // Takes and stores users login information, username and password
{
string username;
string password;
cout << "Please create a username";
cin >> username;
cout << "Please create a password";
cin >> password;
ofstream createaccount;
createaccount.open("accounts.txt");
createaccount << username << " " << password;
createaccount.close();
cout << "Information saved" << endl;
}
void login() // Takes information stored in create account
{
string username;
string password;
cout << "Please enter your username";
cin >> username;
cout << "Please enter your password";
cin >> password;
ifstream savedaccount;
savedaccount.open("accounts.txt");
savedaccount >> username >> password;
savedaccount.close();
cout << "Login successful";
}