Line 34: When calling a function, you don't specify the types of the arguments. So this should be displayBalance(data[i]);. The same applies to lines 40 and 47.
how should i correct it i have no idea...help please...
I would start with the missing int main() function. Seeing the code for mainMenu() would be helpful to know what is actually being returned from the function.
As kingkush noted your switch is not written correctly. There are several parts of the switch that need fixed specifically with the function calls in the case sections.
First part I would work on is getting main and mainMenu working correctly then tackle the switch and other functions.
it says
-[Note] in passing argument 1 of 'void displayBalance(std::ifstream&, Detail*)'
-[Error] invalid initialization of reference of type 'std::ifstream& {aka std::basic_ifstream<char>&}' from expression of type 'Detail'
cout<< "\tYou have opted to withdraw money\n" << endl;
cout<< " Please Enter amount you with to withdraw --Type 0 to return to menu: RM";
cin >> withdraw;
cout<< "\n";
system("cls");
if (withdraw == 0)
{
system("cls");
menu(); //function call
} //end if
else if (withdraw != 0)
{
if (withdraw > data[i] .balance)
{
system("CLS");
cout << "Value Exceeds Current balance Please enter smaller amount\n" << endl;
cout << "Enter Amount you Wish to Withdraw: RM";
cin >> withdraw;
system("CLS");
/* Deposit Menu beings here & prompts user to make chice*/
cout<< "\tYou Have Opted to Deposit Money\n" << endl;
cout<< " Please Enter Amount You Wish to Deposit --";
cout<<"Type 0 to return to Menu: RM";
cin>> deposit;
cout<< "\n";
system("cls");
if (deposit == 0)
{
system("cls");
menu(); //function call
}
else if (deposit != 0)
{
data[i] .balance= data[i] .balance + deposit;
cout << "You Have Successfully added RM" << deposit << " to your Account\n" << endl;
cout << "[UPDATED]Balance RM" << data[i] .balance << "\n" << endl;
Please add code tags to your code. Edit the post, highlight the code and click the <> button to the right of the edit window.
The calls to displayBalance, withdrawFunds and depositFunds don't match the protptype. The y need an addtional argument, the infile. But before you can pass the infile, you have to pass it into menu(). So change menu to
int menu(ifstream &infile) in both the declaration and the definition. Then change all calls to menu() to be menu(infile)
That will a long way to getting the code to compile.
int main()
{
Detail data[4]; // <--- Moved here because it did not work at end of struct.
data[0].pin = 1234; // <--- Added to use with while.
ifstream inFile;
inFile.open("user.txt"); // <--- Opened, but never used. Should call a function to read the file and
// put the information into the "data" structs.
cout << fixed << showpoint << setprecision(2); //Set the numeric output formatting
int pin{ 0 }, i{ 0 }; // <--- These variables need to be initialized.
//char choice;
cout << "\t======================================================\n" << endl;
cout << " \t\t * WELCOME *------\n" << endl;
cout << " WELCOME TO 3A BANKING " << endl;
cout << "=======================================" << endl;
cout << "\t========================================================\n\n" << endl;
cout << "\t\t\t\tUSER LOGIN" << endl;
cout << "\n\t\t\t------ Enter PIN: ";
cin >> pin; // <--- Changed to just pin.
cout << "\n";
while (pin != data[i].pin)
{
system("CLS"); // Clears screen <--- Careful not everyone can use this.
cout << "\t**********************************************************\n" << endl;
cout << " \t\t 3A BANKING \n\n\t\t\t ------* WELCOME *------\n" << endl;
cout << "\t**********************************************************\n\n" << endl;
cout << "\t\t\t\tUSER LOGIN\n" << endl;
cout << "\t\tINVALID PIN WAS ENTERED\n" << endl;
cout << "\n\t\t\t------ Enter PIN: ";
cin >> pin;
cout << "\n";
}//end while
system("CLS");
menu(inFile, data); //function call <--- Needs the parameters for case 2 and 3.
// These lines not necessary as they do not really do anything for the file stream that is never used.
// And the wrong place to put them.
//inFile.clear();
//inFile.ignore(1000, '\n');
inFile.close(); // <--- Added the close and return.
return 0;
The code does raise questions about the intended design. None of the functions (apart from main() ) actually do anything with the file, so it begs the question, what is the purpose of passing it as a parameter to the function?
Another question about the design. The functions receive the array data[] and thus are able to access any of the elements in the array. But which one should be accessed? An uninitialised variable int i is used as the subscript, which is an error in the technical sense as well as making no real sense in terms of what the program is intended to achieve.
Perhaps function main() should identify which specific account is to be accessed, and then rather than passing an array between functions, just pass the particular Detail object (a single element of the array) which is to be accessed?
Those kind of problems should be detected quickly as they are hard to find later. If you find yourself having troubles you can try using a program to help you do that. I tend to use checkmarx sometimes, does a pretty good job.
Good luck!