So I have been writing a program for a bank recording project and when I get to line 23 I get the following error "variable or field 'modify' declared void". I have been looking at other threads on the same topic but none of them seem to be able to answer my problem. I was wondering if someone could take a look at my code and give me suggestions. Much thanks to those who do.
//***************************************************************
// HEADER FILE USED IN PROJECT
//***************************************************************
//***************************************************************
// CLASS USED IN PROJECT
//***************************************************************
class account{
int acno;
char name[50];
int deposit;
char type;
public:
void create_account(); //function to get data from user
void show_account()const; //function to show data on screen
void modify; //function to add new data
void dep(int); //function to accept amount and add to balance amount
void draw(int); //function to accept amount and subtract from balance amount
void report() const; //function to show data in a table format
int retacno() const; //function to return account
int retdeposit() const; //function to return balance amount
char rettype() const; //function to return account type
};
void account::create_account()
{
cout << "\nEnter the account number: ";
cin >> acno;
cout << "\n\nEnter the name of the account holder: ";
cin.ignore();
cin.getline(name,50);
cout << "\nEnter type of the account(C/S): ";
cin >> type;
type=toupper(type);
cout << "\nEnter the initial amount (>=500 for savings >=1000 for current): ";
cin >> deposit;
cout << "\n\n\nAccount Created...";
}
//***************************************************************
// FUNCTION DECLARATION
//***************************************************************
void write_account(); //function to write record in binary file
void display_sp(int); //function to display account details given by user
void modify_account(int); //function to modify record of file
void delete_account(int); //function to delete record of file
void display_all(); //function to display all account details
void deposit_withdraw(int,int); //function to deposit or withdraw amount for given account
void intro; //introductory screen function
//***************************************************************
// THE MAIN FUNCTION OF PROGRAM
//***************************************************************
int main()
{
char ch;
int num;
intro();
do
{
system("cls");
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. NEW ACCOUNT";
cout<<"\n\n\t02. DEPOSIT AMOUNT";
cout<<"\n\n\t03. WITHDRAW AMOUNT";
cout<<"\n\n\t04. BALANCE ENQUIRY";
cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST";
cout<<"\n\n\t06. CLOSE AN ACCOUNT";
cout<<"\n\n\t07. MODIFY AN ACCOUNT";
cout<<"\n\n\t08. EXIT";
cout<<"\n\n\tSelect Your Option (1-8) ";
cin>>ch;
system("cls");
switch(ch)
{
case '1':
write_account();
break;
case '2':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
deposit_withdraw(num, 1);
break;
case '3':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
deposit_withdraw(num, 2);
break;
case '4':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
display_sp(num);
break;
case '5':
display_all();
break;
case '6':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
delete_account(num);
break;
case '7':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
modify_account(num);
break;
case '8':
cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :cout<<"\a";
}
cin.ignore();
cin.get();
}while(ch!='8');
return 0;
Thank you for helping me fix the parentheses. Can you explain to me what the error means so that if it happens again in another situation I know what I should look for and what I should do?
Currently, your declaration of modify matches the way you'd declare a variable, which is also called a field when declared inside of a class.
It's just like how you declare int deposit;, except the type is void instead of int. But in C++, a variable or field cannot have the type void, so it says that the error is that you have a variable or field that has been declared as void. It would be nice if the compiler would see that you declared 'modify' as function further down, to give you a better error message, but alas, it spits out the first thing it sees wrong.