error

why it says there [Error] expected primary-expression before 'inFile'??


[#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <fstream>
using namespace std;

struct Detail
{
int AccNum;
int pin;
char userName[100];
double balance;
}data[4];



int mainMenu();
int menu();
void displayBalance(ifstream & ,Detail data[]);
void withdrawFunds(ifstream & ,Detail data[]);
void depositFunds(ifstream & ,Detail data[]);


int menu()
{

int i;
switch (mainMenu())
{

case 1:
system("cls");
displayBalance(ifstream inFile& data[i]);
menu(); //function call
break;

case 2:
system("cls");
withdrawFunds(ifstream inFile& data[i]);
menu(); //function call
break;


case 3:
system("cls");
depositFunds(ifstream inFile& data[i]);
menu(); //function call
break;


case 4:
exit(0);
break;


default:
cout << "\nINVALID ENTRY.... Please Select numbers 1 - 4\n" << endl << endl;
system("pause");
menu(); //function call
break;

}//end switch


system("pause");
return 0;


}//end menu()]
This is easier to read:

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
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <fstream>
using namespace std;

struct Detail 
{
int AccNum;
int pin;
char userName[100];
double balance;
}data[4];



int mainMenu();
int menu();
void displayBalance(ifstream & ,Detail data[]);
void withdrawFunds(ifstream & ,Detail data[]);
void depositFunds(ifstream & ,Detail data[]);


int menu()
{

int i;
switch (mainMenu())
{

case 1:
system("cls");
displayBalance(ifstream inFile& data[i]);
menu(); //function call
break;

case 2:
system("cls");
withdrawFunds(ifstream inFile& data[i]);
menu(); //function call
break;


case 3:
system("cls");
depositFunds(ifstream inFile& data[i]);
menu(); //function call
break;


case 4:
exit(0);
break;


default:
cout << "\nINVALID ENTRY.... Please Select numbers 1 - 4\n" << endl << endl;
system("pause");
menu(); //function call
break;

}//end switch


system("pause");
return 0;


}//end menu()
Unless mainMenu() is an int (Your cases are int 1, 2...) your switch statement is not written correctly.
Last edited on
how should i correct it i have no idea...help please...
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.
Hello Aini Sley,

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.

Hope that helps,

Andy
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'

what should i do??

this my full coding ..

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <fstream>
using namespace std;

struct Detail
{
int pin;
int AccNum;
char userName[100];
double balance;
}data[4];



int mainMenu();
int menu();
void displayBalance(ifstream & ,Detail data[]);
void withdrawFunds(ifstream & ,Detail data[]);
void depositFunds(ifstream & ,Detail data[]);



int main()
{

ifstream inFile;
inFile.open("user.txt");

cout << fixed << showpoint << setprecision(2); //Set the numeric output formatting

int pin,i;
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 >>data[i] .pin;
cout << "\n";

while (pin != data[i] .pin)
{
system("CLS"); // Clears screen

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(); //function call

inFile.clear();
inFile.ignore(1000,'\n');
}//end main()

int menu()
{
int i;
switch (mainMenu())
{

case 1:
system("cls");
displayBalance( & data[i]);
menu(); //function call
break;

case 2:
system("cls");
withdrawFunds(data[i]);
menu(); //function call
break;


case 3:
system("cls");
depositFunds(data[i]);
menu(); //function call
break;


case 4:
exit(0);
break;


default:
cout << "\nINVALID ENTRY.... Please Select numbers 1 - 4\n" << endl << endl;
system("pause");
menu(); //function call
break;

}//end switch


system("pause");
return 0;


}//end menu()


int mainMenu()
{

system("cls");


int input;

cout<< "\t____________________________________________\n" << endl;
cout<< "\t" << " ************* MENU *************" << endl;
cout<< "\t____________________________________________\n\n" << endl;


cout << "\tPlease Enter the number for the Transaction\n" << endl;
cout <<"\t\tPress 1. ----->> Balance Inquiry\n" << endl;
cout << "\t\tPress 2. ----->> Withdrawal\n" << endl;
cout <<"\t\tPress 3. ----->> Deposit\n" << endl;
cout <<"\t\tPress 4. ----->> Exit\n" << endl;

cout << "\t_________________________________________\n" << endl;
cout << "\t ENTER YOUR CHOICE:- ";
cin >> input;


return input;
}//end mainMenu()


void displayBalance(ifstream& inFile,Detail data[])
{
for (int i=0;i<4;i++)
{
cout << "\nAccount Owner is: RM" << data[i] .userName << "\n" << endl;
cout << "\nAccount Number is: RM" << data[i] .AccNum << "\n" << endl;
cout << "\nAccount Balance is: RM" << data[i] .balance << "\n" << endl;
}



system("PAUSE");
system("CLS");
}//end displayBalance()


/*------------------------------------*****function definition*****------------------------------------*/
void withdrawFunds(ifstream& inFile,Detail data[])
{

int i;
double withdraw = 0.0;


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");


if (withdraw == 0)
{

system("cls");

menu(); //function call
} //end if


cout << "\nAmount Withdrawn: RM" << withdraw << "\n" << endl;
data[i] .balance = data[i] .balance - withdraw;
cout << "[UPDATED]Balance : RM" << data[i] .balance << "\n" << endl;

system("PAUSE");
system("CLS");
} //end if


else
{

cout << "\nAmount Withdrawn: RM" << withdraw <<endl;
data[i] .balance= data[i] .balance - withdraw;
cout << "\n[UPDATED]Balance: RM" << data[i] .balance<< "\n" << endl;

system("PAUSE");
system("CLS");
} //end else
}//end else if
}//end withdrawFunds()


/*-----------------------------------*****function definition*****--------------------------------------*/
void depositFunds(ifstream inFile,Detail data[])
{

int i;
double deposit = 0.0;


/* 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;


system("pause");
system("cls");
}
}//end depositFunds()
Last edited on
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.
Hello Aini Sley,

And ammended main function. Read the comments:

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
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;


Hope that helps,

Andy
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?
i keep sending reply but is it not show it ??
okay now it works..
how is it possible to identify which specific account is to be accessed?maybe i should give it a try but i dont know what to use..
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!
Topic archived. No new replies allowed.