I am making a program with which to save banking information (i.e., account, password, balance). I am having trouble with a certain error but I'm not sure of the cause.
Here is the entire code.
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
int x = 0;
void addUser();
void login();
void deposit();
void withdrawl();
struct bankUser
{
double balance;
string account, password;
};
bankUser user[20];
int menu()
{
ofstream myfile("bankmachine.txt", ios::app);
char choice;
cout << "1) Add account" << endl;
cout << "2) Log in" << endl;
cout << "3) Make deposit" << endl;
cout << "4) Make withdrawl" << endl;
cout << "5) Quit" << endl << endl;
cout << "What would you like to do?: ";
cin >> choice;
cout << endl;
switch (choice)
{
case '1':
addUser();
break;
case '2':
login();
break;
case '3':
deposit();
break;
case '4':
withdrawl();
break;
case '5':
myfile << user[x].balance << endl;
myfile.close();
cout << "Thank you for using the banking system." << endl << endl;
system ("pause");
return 0;
break;
default:
cout << "That is not a valid option. Please choose again." << endl << endl;
menu();
}
}
void addUser()
{
if ((x >= 0) && (x < 20))
{
cout << "Please enter your desired account name: ";
cin >> user[x].account; // Account name.
cout << "Thank you, now please enter your desired password: ";
cin >> user[x].password; // Account password.
cout << "\nAccount created. You may now log in." << endl << endl;
ofstream myfile("bankmachine.txt", ios::app); // Opens the text file at the end of the file (if data is already present).
myfile << user[x].account << endl; // Writes to text file.
myfile << user[x].password << endl; // ^
myfile.close(); // Close text file (important).
x++; // Increases to simulate the addition of another user.
menu();
}
else // Will display if user has entered 20 users.
{
cout << "You have entered the maximum number of users." << endl;
menu();
}
}
void deposit()
{
int deposit;
string answer;
do
{
cout << "Please enter the amount of money that you would like to deposit: ";
cin >> deposit;
user[x].balance += deposit;
cout << "Thank you. Your new balance is " << user[x].balance << "." << endl << endl;
cout << "Would you like to make another deposit? (Y/N): ";
cin >> answer;
} while ((answer != "N") && (answer == "Y"));
cout << endl;
menu();
}
void withdrawl()
{
int withdraw;
string answer;
do
{
cout << "Please enter the amount of money that you would like to withdraw: ";
cin >> withdraw;
if (withdraw <= user[x].balance)
{
user[x].balance -= withdraw;
}
else
{
cout << "\nSorry, you do not have sufficient funds to complete this withdrawl.\nPlease try again." << endl << endl;
withdrawl();
}
cout << "Thank you. Your new balance is " << user[x].balance << "." << endl << endl;
cout << "Would you like to make another withdrawl? (Y/N): ";
cin >> answer;
} while (answer != "N" && answer == "Y");
cout << endl;
menu();
}
void login() // Function to log in.
{
string user, pw, usernameCheck, passwordCheck;
double balance;
cout << "Please enter your login information." << endl << endl;
cout << "Account name: ";
cin >> user;
cout << "Password: ";
cin >> pw;
cout << endl;
ifstream myfile("bankmachine.txt", ios::app);
while (!myfile.eof()) // Loops until end of file.
{
getline(myfile, usernameCheck);
if (usernameCheck == user)
{
getline(myfile, passwordCheck);
if (passwordCheck == pw)
{
myfile >> balance;
cout << "Login successful." << endl;
cout << "Your balance is " << balance << "." << endl << endl;
user[x].balance = balance;
}
else // If not, display:
{
cout << "Password incorrect." << endl << endl;
}
}
}
myfile.close(); // Close text file (important).
menu();
}
int main()
{
cout << "Welcome to the banking system." << endl << endl;
menu();
}
I keep getting this error (on line 172):
request for member 'balance' in 'user.std::basic_string<_CharT, _Traits,
_Alloc>::operator[] [with _CharT = char, _Traits = std::char_traits<char>, _Alloc =
std::allocator<char>](((unsigned int)x))', which is of non-class type 'char'|
What is this caused by? How can I fix it? Any answers are appreciated.
Judging by the error provided it seems as if user is not of type struct bankUser, but a std::string.
You are trying to assign a std::string (balance) to character at offset x of your std::string named user, which is doomed to fail.
TL;DR user is not declared to be a struct bankUser.
Related
I am trying to build a menu on console on C++ with CodeBlock. Is for a course.
I would like to validate garbage enter by the user. For example, the user have to enter a number. If he enters a wrong number, no problem, the program work and continue. But if He enters a letter or some garbage, the program start on infinite loop.
I cannot use system(PAUSE) because I am programming on Linux.
I tried some code like cin.get() or do while with cin.get() but no result.
Here is my code :
#include <iostream>
using namespace std;
void showMenu()
{
cout << "---------------MENU --------------" << endl;
cout << "1- Check balance :" << endl;
cout << "2- Check deposit :" << endl;
cout << "3- Withdraw:" << endl;
cout << "4- Exit" << endl;
cout << "--------------------------------" << endl;
}
int main()
{
int option;
double balance = 500;
do
{
showMenu();
cout << "Option: ";
cin >> option;
cout << "\033[2J\033[1;1H";
switch(option)
{
case 1:
cout << "Balance is: " << balance << " $" << endl;
break;
case 2:
cout << "Deposit amount: " << endl;
double depositAmount;
cin >> depositAmount;
balance += depositAmount;
break;
case 3:
cout << "Withdraw amount: " << endl;
double withdrawAmount;
cin >> withdrawAmount;
if (withdrawAmount <= balance) {
balance -= withdrawAmount;
}
else {
cout << "Not enough money" << endl;
}
break;
default:
cout << "Your choice is invalid ";
do {
cout << '\n' << "Press the Enter key to continue.";
}while (cin.get() != '\n');
}
} while(option != 4);
return 0;
}
Do you have an idea how can I validate easily the garbage enter by the user ?
Thank you for your Help
It works with the code on default part : cin.clear and cin.ignore(). This last one is important. Thank you to user4581301
#include <iostream>
using namespace std;
void showMenu()
{
cout << "---------------MENU --------------" << endl;
cout << "1- Check balance :" << endl;
cout << "2- Check deposit :" << endl;
cout << "3- Withdraw:" << endl;
cout << "4- Exit" << endl;
cout << "--------------------------------" << endl;
}
int main()
{
int option;
double balance = 500;
do
{
showMenu();
cout << "Option: ";
cin >> option;
cout << "\033[2J\033[1;1H";
switch(option)
{
case 1:
cout << "Balance is: " << balance << " $" << endl;
break;
case 2:
cout << "Deposit amount: " << endl;
double depositAmount;
cin >> depositAmount;
balance += depositAmount;
break;
case 3:
cout << "Withdraw amount: " << endl;
double withdrawAmount;
cin >> withdrawAmount;
if (withdrawAmount <= balance) {
balance -= withdrawAmount;
}
else {
cout << "Not enough money" << endl;
}
break;
default:
cout << "\033[2J\033[1;1H"; //for clean screen with Linux
cout << "Your choice is invalid " << endl;
cin.clear();
cin.ignore();
}
} while(option != 4);
return 0;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
#include <iostream>
using namespace std;
// ATM menu
void Menu()
{
cout << " MENU " << endl;
cout << "1.Deposit" << endl;
cout << "2.Balance" << endl;
cout << "3.Withdraw" << endl;
cout << "4.Transfer" << endl;
cout << "5.Exit" << endl;
cout << "-------------------------------" << endl;
}
// Tasks of ATM
int Task(int balance, int balance2, int option)
{
int amount;
cin >> option;
switch(option)
{
case 1:
cout << "please enter the amount" << endl;
cin >> amount;
balance += amount;
cout << "your balance is now:" << balance << "$" << endl;
break;
case 2:
cout << balance << endl;
break;
case 3:
cout << "please enter the amount" << endl;
cin >> amount;
if(amount <= balance)
{
balance -= amount;
cout << "your balance is now:" << balance << "$" << endl;
break;
}
else
cout << "insufficent amount";
break;
case 4:
cout << "please enter the amount" << endl;
cin >> amount;
if(amount <= balance)
{
balance -= amount;
balance2 += amount;
cout << "your balance is now:" << balance << "$" << endl;
break;
}
else
cout << "insufficent amount";
break;
}
}
// Main func
int main1()
{
cout << "Please choose Your account " << endl;
int Account1, Account2;
cout << "Account 1 , Account 2" << endl;
char x;
cin >> x;
int option;
// Account 1 lines:Balance = 500 , balance 2= 700
do
{
if(x == Account1)
{
Menu();
cout << "option:" << endl;
cin >> option;
Task(500, 700, option);
}
// Account 2 lines : Balance = 700 , balance 2= 500
else
{
int option;
cout << "option:" << endl;
cin >> option;
Task(700, 500, option);
}
} while(option != 5);
}
im new to c++ and i did some coding which looks like like this and when i try to build the executable file i get this error: no return statement in function returning non void [-Wreturn-type] in line 40 and 64.i really have no idea what the problem is and i searched alot in the internet to understand what it is but i didn't understand the explanations at all.
It's a really simple solution. You created int function that never returns a value. If you have a function that you don't want any value to be returned, just make it void. To make your code work simply change function type from int to void
void Task(int balance, int balance2, int option)
The second issue is that you did declare balance1 and balance2, but you forgot to declare their values which lead to another error ( how is the compiler supposed to know their starting value?):
int Account1; Account2; // incorrect
int Account1=0, Account2=0; //fixed
Of course, you can also set these values later, but in this case, you should do it while declaring.
Another thing, why do you have int main1() function?
compiler will not treat it as you desire - it has to be called int main()
in order to do what you want.
You are missing "return balance" at the end of the Task() function. You define your function to return integer, that means you have to have return statement inside the function. Also, you have to have main() function, not main1() as in your case. Every C/C++ needs function that is called main() and it represent the entry point of the program. Try this code:
#include <iostream>
using namespace std;
// ATM menu
void Menu() {
cout << " MENU " << endl;
cout << "1.Deposit" << endl;
cout << "2.Balance" << endl;
cout << "3.Withdraw" << endl;
cout << "4.Transfer" << endl;
cout << "5.Exit" << endl;
cout << "-------------------------------" << endl;
}
// Tasks of ATM
int Task(int balance, int balance2, int option) {
int amount;
cin >> option;
switch (option) {
case 1:
cout << "please enter the amount" << endl;
cin >> amount;
balance += amount;
cout << "your balance is now:" << balance << "$" << endl;
break;
case 2:
cout << balance << endl;
break;
case 3:
cout << "please enter the amount" << endl;
cin >> amount;
if (amount <= balance) {
balance -= amount;
cout << "your balance is now:" << balance << "$" << endl;
break;
} else
cout << "insufficent amount";
break;
case 4:
cout << "please enter the amount" << endl;
cin >> amount;
if (amount <= balance) {
balance -= amount;
balance2 += amount;
cout << "your balance is now:" << balance << "$" << endl;
break;
} else
cout << "insufficent amount";
break;
}
return balance;
}
// Main func
int main() {
cout << "Please choose Your account " << endl;
int Account1, Account2;
cout << "Account 1 , Account 2" << endl;
char x;
cin >> x;
int option;
// Account 1 lines:Balance = 500 , balance 2= 700
do {
if (x == Account1) {
Menu();
cout << "option:" << endl;
cin >> option;
Task(500, 700, option);
}
// Account 2 lines : Balance = 700 , balance 2= 500
else {
int option;
cout << "option:" << endl;
cin >> option;
Task(700, 500, option);
}
} while (option != 5);
}
I am getting a runtime error when the program is running it takes the username but then when it comes for password it shows me: Debug Error Run Time Check Failure #3-T.
#include <iostream>
using namespace std;
int main()
{
int choice;
float username, password; //login
int name, age, gender, dob, address, workinfo;
cout << "Welcome To HDFC Bank" << endl;
//Menu Option
cout << "Choose an option: " << endl;
cout << "===========================" << endl;
cout << "1. Login" << endl;
cout << "2. Register" << endl;
cout << "===========================" << endl;
cin >> choice;
if (choice == 1) {
cout << "Please Enter Your Username: " << endl;
cin >> username;
cout << "Please Enter your Password: " << endl;
cin >> password;
if (choice == 1 || password = 2) {
cout << "Welcome To The Program!!!" << endl;
}
else {
cout << "Wrong Details!!" << endl;
}
}
else if (choice == 2) {
cout << "Enter Your Full Name: " << endl;
cin >> name;
cout << "Enter Your Age" << endl;
cin >> age;
cout << "Enter Your Date of Birth(dd/mm/yyyy): " << endl;
cin >> dob;
cout << "Enter Your Gender(M/F)" << endl;
cin >> gender;
cout << "Enter Your Address: " << endl;
cin >> address;
cout << "Enter Your Work Details: " << endl;
cin >> workinfo;
}
if (age < 21) {
cout << "Sorry You cannot Register as you are below 21 years. Please try later." << endl;
}
else {
cout << "You have succesfully registered. Please check your email." << endl;
}
return 0;
}
You should definitely learn more about Types and STL Streams.
But assuming you're experimenting here is little bit more meaningful version of your code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int choice = 0;
std::string username, password; //login
int age = 0;
std::string name, gender, dob, address, workinfo;
cout << "Welcome To HDFC Bank" << endl;
//Menu Option
cout << "Choose an option: " << endl;
cout << "===========================" << endl;
cout << "1. Login" << endl;
cout << "2. Register" << endl;
cout << "===========================" << endl;
cin >> choice;
cin.ignore();
if (choice == 1) {
cout << "Please Enter Your Username: " << endl;
getline(cin, username);
cout << "Please Enter your Password: " << endl;
getline(cin, password);
if (password == "1" || password == "2") {
cout << "Welcome To The Program!!!" << endl;
}
else {
cout << "Wrong Details!!" << endl;
return 0;
}
}
else if (choice == 2) {
cout << "Enter Your Full Name: " << endl;
getline(cin, name);
cout << "Enter Your Age: " << endl;
cin >> age;
cin.ignore();
cout << "Enter Your Date of Birth(dd/mm/yyyy): " << endl;
getline(cin, dob);
cout << "Enter Your Gender(M/F)" << endl;
getline(cin, gender);
cout << "Enter Your Address: " << endl;
getline(cin, address);
cout << "Enter Your Work Details: " << endl;
getline(cin, workinfo);
}
if (age < 21) {
cout << "Sorry You cannot Register as you are below 21 years. Please try later." << endl;
}
else {
cout << "You have successfully registered. Please check your email." << endl;
}
return 0;
}
Note that we use cin.ignore() after reading int as described here
I'm trying to get this program to run properly. it should do as the pseudo code do as described although when I execute the program and try to open a new account if I put more than one character in the customer name field the program just goes into an infinite loop and I have clue how to fix this issue.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <conio.h>
#include <iomanip>
using namespace std;
int choice, account_number;
long acc_entry;
long acc_no = 112280;
double balance, deposit, withdrawal;
int interest = 1.67;
string customer_name;
void display_menu();
void get_choice();
void menu_selection(int selection);
void open_account();
void make_withdrawal();
void make_deposit();
void add_interest();
void display_transaction();
void main()
{
get_choice();
}
void display_menu()
{
system("CLS");
cout << "\n\n\t\t\t\tACCOUNT MENU";
cout << "\n\t\t\t\t============\n";
cout << "\n\t\t\t\t1. Open Account";
cout << "\n\t\t\t\t2. Make Withdrawal";
cout << "\n\t\t\t\t3. Make Deposit";
cout << "\n\t\t\t\t4. Add Interest";
cout << "\n\n\t\t\t\t5. Exit";
}
void open_account()
{
system("CLS");
cout << "\n\n\t\t\t\tOPEN ACCOUNT";
cout << "\n\t\t\t\t============\n\n";
cout << "\tPlease enter your name\n\n\t";
cin >> customer_name;
cout << "\n\n\tPlease enter initial despoit\n\n\t";
cin >> deposit;
balance = balance + deposit;
account_number = acc_no + 1;
cout << "\n\n\tYour new account number\n\n\t" << setfill('0') << setw(8) << account_number;
get_choice();
}
void make_withdrawal()
{
system("CLS");
cout << "\n\n\t\t\t\tMAKE WITHDRAWAL";
cout << "\n\t\t\t\t===============\n\n";
cout << "\tPlease enter Account Number\n\n\t";
cin >> acc_entry;
if (acc_entry == account_number)
{
cout << "\n\n\tPlease enter amount to withdraw\n\n\t";
cin >> withdrawal;
if (withdrawal > balance)
{
cout << "\n\n\tYou are exceeding your limit";
cin.ignore();
cin.get();
}
else
{
balance = balance - withdrawal;
cout << "\n\n\tYour new balance\n\n\t" << fixed << setprecision(2) << (char)156 << balance;
cin.ignore();
cin.get();
}
}
else
{
cout << "\n\n\tAccount number does not exist.";
cin.ignore();
cin.get();
}
get_choice();
}
void make_deposit()
{
system("CLS");
cout << "\n\n\t\t\t\tMAKE DEPOSIT";
cout << "\n\t\t\t\t============\n\n";
cout << "\tPlease enter Account Number\n\n\t";
cin >> acc_entry;
if (acc_entry == account_number)
{
cout << "\n\n\tPlease enter amount to deposit\n\n\t";
cin >> deposit;
balance = balance + deposit;
cout << "\n\n\tYour new balance\n\n\t" << fixed << setprecision(2) << (char)156 << balance;
cin.ignore();
cin.get();
}
else
{
cout << "\n\n\tAccount number does not exist.";
cin.ignore();
cin.get();
}
get_choice();
}
void add_interest()
{
string yn;
system("CLS");
cout << "\n\n\t\t\t\tADD INTEREST";
cout << "\n\t\t\t\t============\n\n";
cout << "\tPlease enter Account Number\n\n\t";
cin >> acc_entry;
if (acc_entry == account_number)
{
cout << "\n\n\tDo you wish to add interest [Y/N]\n\n\t";
getline(cin, yn);
if (yn == "Y" || yn == "y")
{
balance = balance * interest;
cout << "\n\n\tYour new balance\n\n\t" << fixed << setprecision(2) << (char)156 << balance;
cin.ignore();
cin.get();
}
}
else
{
cout << "\n\n\tAccount number does not exist.";
cin.ignore();
cin.get();
}
get_choice();
}
void display_transaction()
{
system("CLS");
cout << "\n\n\t\t\t\tCLOSED";
cout << "\n\t\t\t\t======\n\n";
if (account_number != 112280)
{
cout << "\tCustomer Name : - " << customer_name;
cout << "\n\n\tAccount Number : - " << setfill('0') << setw(8) << account_number;
cout << "\n\n\tBalance : - " << fixed << setprecision(2) << (char)156 << balance << "\n\n";
}
cin.get();
}
void get_choice()
{
display_menu();
do
{
cout << "\n\n\t\t\t\tEnter Number [1-5] : ";
cin >> choice;
menu_selection(choice);
} while
(choice << 1 || choice >> 5);
cin.ignore();
}
void menu_selection(int a)
{
switch (a)
{
case 1:
{
open_account();
break;
}
case 2:
{
make_deposit();
break;
}
case 3:
{
make_withdrawal();
break;
}
case 4:
{
add_interest();
break;
}
case 5:
{
display_transaction();
break;
}
default:
{
cout << "hello";
}
}
}
void get_choice()
{
display_menu();
do
{
cout << "\n\n\t\t\t\tEnter Number [1-5] : ";
cin >> choice;
menu_selection(choice);
} while
(choice < 1 || choice > 5); // << and >> aren't for comparison
cin.ignore();
}
In your get_choice function, you have a do-while loop with the following condition:
while (choice << 1 || choice >> 5); // this is going to run for a bit
<< and >> are not comparison operators; rather, they are bit shift operators.
Because your choice can be shifted either left or right, it goes into an infinite loop. It's a simple fix, really - change them to comparison operators!
As for the customer name, if there are spaces or newlines, std::cin will stop reading at the first one. Be sure to use std::getline for reading strings from stdin.
In open_account, replace this:
cin >> customer_name;
with this:
std::getline(cin, customer_name);
Also, fix this line:
int interest = 1.67; // This should be a double
You shouldn't be using globals really, but that's a whole different story.
I am trying to make a banking program that can read a username and password from a text file, and compare it to what the user enters. I have searched and tried a few different methods but I can't seem to get it to work. Im sorry if this is a re-post I just can't figure it out.
I am very new to coding so please forgive my mistakes.
The text file I have is called : "Account.txt"
It contains "username" on the first line then "userpassword" on the second line.
/*
Hunter Walker 11/10/2015
Banking Application with Input validation
Assignment 2
*/
//Headers
#include<iostream>
#include<string>
#include<cstdlib>
#include <fstream>
using namespace std;
//Variables
char input1, input2;
string username,userpassword, newusername, newuserpassword;
string customuser, custompass;
double amountin, amountout;
double total = 0;
//Function declarations
int bankingmenu();
int newaccount();
int login();
int main();
int mainmenu();
int deposit();
int withdraw();
int showbalance();
//Code to read from file
// The main menu for the banking application
int mainmenu()
{
cout << "Hi! Welcome to Future Computer Programmer ATM Machine!" << endl;
cout << "Please select an option from the menu below:" << endl;
cout << "l -> Login " << endl;
cout << "c -> Create New Account " << endl;
cout << "q -> Quit " << endl;
cin >> input1;
return 0;
}
// Function to allow the user to make a new account
int newaccount()
{
cout << "**********************************" << endl;
cout << "Welcome to the create an account menu!" << endl;
cout << "Please enter your desired username:" << endl;
cin >> newusername;
cout << "Please enter a password for your account:" << endl;
cin >> newuserpassword;
cout << "Thank you for creating an account with Future Computer Programmer ATM Machine!" << endl;
cout << "Your username is " << newusername << " and your password is " << newuserpassword << "." << endl;
cout << endl;
cout << "Reminder: Don't share your username or password with anyone." << endl;
cout << endl;
cout << "**********************************" << endl;
}
// Function to allow user to login to their account
int login()
{
cout << "Please enter username:" << endl;
cin >> username;
cout << "Please enter password:" << endl;
cin >> userpassword;
ifstream inputFile;
inputFile.open("Account.txt");
cout << customuser << " " << custompass << endl;
if (customuser == username && custompass == userpassword)
{
bankingmenu();
}
else
{
cout << "User name or password incorrect!" << endl;
cout << "Returning to main menu!" << endl;
return main();
}
inputFile.close();
return 0;
}
// The secondary menu for withdrawing/depositing/ or checking balance
int bankingmenu()
{
cout << "*******************************" << endl;
cout << "Please select an option from the menu below::" << endl;
cout << " d -> Deposit Money" << endl;
cout << " w -> Withdraw Money" << endl;
cout << " r -> Request Balance" << endl;
cout << " q -> Quit" << endl;
cin >> input2;
if (input2 == 'd')
{
deposit();
}
else if (input2 == 'w')
{
withdraw();
}
else if (input2 == 'r')
{
showbalance();
}
else if (input2 == 'q')
{
cout << "Returning to main menu! " << endl;
return main();
}
else
{
cout << "Please select a valid input and try again!" << endl;
return bankingmenu();
}
return 0;
}
// Function to allow to deposit to account
int deposit()
{
cout << "Please enter the amount of money you wish to deposit:" << endl;
cin >> amountin;
total = amountin + total;
cout << "The deposit was a success! Thanks for using Future Computer Programmer ATM Machine!" << endl;
return bankingmenu();
}
// Function to allow user to withdraw from account
int withdraw()
{
cout << "Please enter the amount you would like to withdraw:" << endl;
cin >> amountout;
if (total < amountout)
{
cout << "You can't withdraw more money than you have!" << endl;
cout << "Please select a different amount to withdraw." << endl;
return withdraw();
}
else
{
cout << "The amount has been withdrawn." << endl;
total = total - amountout;
return bankingmenu();
}
}
// Function to display the balance
int showbalance()
{
cout << "The balance in your account is $" << total << "." << endl;
return bankingmenu();
}
// The main function that calls all previous functions to run
int main()
{
mainmenu();
// Option to login
if (input1 == 'l')
{
login();
}
// Option to make a new account
else if (input1 == 'c')
{
newaccount();
}
// Option to exit program
else if (input1 == 'q')
{
cout << "Thanks for using the Future Computer Programmer ATM Machine! " << endl;
cout << "The program will now exit!" << endl;
return 0;
}
// Input validation
else
{
cout << "Please select a valid menu option and try again!" << endl;
return main();
}
return 0;
}
IN the newAccount function you will have to store the username and password with the following lines of code.
ofstream outfile;
outfile.open("Account.txt");
outfile<<newusername<<endl;
outfile<<newpassword<<endl;
outfile.close();
In your login function you will have to add the following two lines of code after you open the file 'Account.txt'
inputFile>>customuser;
inputFile>>custompass;
This would solve the present issue of getting the username and password of single user. But, you'll still have to figure out a way to get usernames and passwords for multiple users who'll use your application.
An easier adaptation to deal with multiple users would be to simply append username and password to the file and search for the username and password sequentially.
An alternative to the above approach is to use a database to store username and password.