c++ - error C2440 in driver file -
i keep receiving error on driver program. have develop driver program. driver program print menu allowing user choose option want. have never created driver program before, pretty rough.
the error:
cpp(38) error c2440: '=' : cannot convert 'void (__cdecl *)(void)' 'int'
what have tried:
-i have tried changing variables int void, vice-versa.
//banking system driver program #include "bankingsystem.h" // account class definition #include <iostream> #include <fstream> #include <iomanip> #include <cstdlib> // exit function prototype using namespace std; void enterchoice(); void createtextfile( fstream& ); void updaterecord( fstream& ); void newrecord( fstream& ); void deleterecord( fstream& ); void outputline( ostream&, const account & ); int getaccount( const char * const ); enum choices { print = 1, update, new, delete, end }; int main() { // open file reading , writing fstream inoutcredit( "credit.dat", ios::in | ios::out | ios::binary ); // exit program if fstream cannot open file if ( !inoutcredit ) { cerr << "file not opened." << endl; exit ( 1 ); } // end if int choice; // store user choice // enable user specify action ***while ( ( choice = enterchoice ) != end )*** **-----line 38** { switch ( choice ) { case print: // create text file record file createtextfile( inoutcredit ); break; case update: // update record updaterecord( inoutcredit ); break; case new: // create record newrecord( inoutcredit ); break; case delete: // delete existing record deleterecord( inoutcredit ); break; default: // display error if user not select valid choice cerr << "incorrect choice" << endl; break; } // end switch inoutcredit.clear(); // reset end-of-file indicator } // end while } // end main // enable user input menu choice int enterchoice() { // display available options std::cout << "\nenter choice" << endl << "1 - store formatted text file of accounts" << endl << "2 - called \"print.txt\" printing" << endl << "3 - update account" << endl << "4 - add new account" << endl << "5 - delete account" << endl << "6 - end program\n? "; int menuchoice; std::cin >> menuchoice; // input menu selection user return menuchoice; } // end function enterchoice // create formatted text file printing void createtextfile( fstream &readfromfile ) { // create text file ofstream outprintfile( "print.txt", ios::out ); // exit program if ofstream cannot create file if ( !outprintfile ) { cerr << "file not created." << endl; exit( 1 ); } // end if outprintfile << left << setw( 10 ) << "account" << setw( 16 ) << "last name" << setw( 11 ) << "first name" << right << setw( 10 ) << "balance" << endl; // set file-position pointer beginning of readfromfile readfromfile.seekg( 0 ); // read first record record file account client; readfromfile.read( reinterpret_cast< char * >( &client ), sizeof( account ) ); // copy records record file text file while ( !readfromfile.eof() ) { // write single record text file if ( client.getaccountnumber() != 0 ) // skip empty records outputline( outprintfile, client ); // read next record record file readfromfile.read( reinterpret_cast< char * >( &client ), sizeof( account ) ); } // end while } // end function createtextfile // update balance in record void updaterecord( fstream &updatefile ) { // obtain number of account update int accountnumber = getaccount( "enter account update" ); // move file-position pointer correct record in file updatefile.seekg( ( accountnumber - 1 ) * sizeof( account ) ); // read first record file account client; updatefile.read( reinterpret_cast< char * >( &client ), sizeof( account ) ); // update record if ( client.getaccountnumber() != 0 ) { outputline( cout, client ); // display record // request user specify transaction std::cout << "\nenter charge (+) or payment (-): "; double transaction; // charge or payment std::cin >> transaction; // update record balance double oldbalance = client.getbalance(); client.setbalance( oldbalance + transaction ); outputline( cout, client ); // display record // move file-position pointer correct record in file updatefile.seekp( ( accountnumber - 1 ) * sizeof( account ) ); // write updated record on old record in file updatefile.write( reinterpret_cast< const char * >( &client ), sizeof( account ) ); } // end if else // display error if account not exist cerr << "account #" << accountnumber << " has no information." << endl; } // end function updaterecord // create , insert record void newrecord( fstream &insertinfile ) { // obtain number of account create int accountnumber = getaccount( "enter new account number" ); // move file-position pointer correct record in file insertinfile.seekg( ( accountnumber - 1 ) * sizeof( account ) ); // read record file account client; insertinfile.read( reinterpret_cast< char * >( &client ), sizeof( account ) ); // create record, if record not exist if ( client.getaccountnumber() == 0 ) { string lastname; string firstname; double balance; // user enters last name, first name , balance std:: cout << "enter lastname, firstname, balance\n? "; std::cin >> lastname; std::cin >> firstname; std::cin >> balance; // use values populate account values client.setlastname( lastname ); client.setfirstname( firstname ); client.setbalance( balance ); client.setaccountnumber( accountnumber ); // move file-position pointer correct record in file insertinfile.seekp( ( accountnumber - 1 ) * sizeof( account ) ); // insert record in file insertinfile.write( reinterpret_cast< const char * >( &client ), sizeof( account ) ); } // end if else // display error if account exists cerr << "account #" << accountnumber << " contains information." << endl; } // end function newrecord // delete existing record void deleterecord( fstream &deletefromfile ) { // obtain number of account delete int accountnumber = getaccount( "enter account delete" ); // move file-position pointer correct record in file deletefromfile.seekg( ( accountnumber - 1 ) * sizeof( account ) ); // read record file account client; deletefromfile.read( reinterpret_cast< char * >( &client ), sizeof( account ) ); // delete record, if record exists in file if ( client.getaccountnumber() != 0 ) { account blankclient; // create blank record // move file-position pointer correct record in file deletefromfile.seekp( ( accountnumber - 1 ) * sizeof( account ) ); // replace existing record blank record deletefromfile.write( reinterpret_cast< const char * >( &blankclient ), sizeof( account ) ); std::cout << "account #" << accountnumber << " deleted.\n"; } // end if else // display error if record not exist cerr << "account #" << accountnumber << " empty.\n"; } // end deleterecord // display single record void outputline( ostream &output, const account &record ) { output << left << setw( 10 ) << record.getaccountnumber() << setw( 16 ) << record.getlastname() << setw( 11 ) << record.getfirstname() << setw( 10 ) << setprecision( 2 ) << right << fixed << showpoint << record.getbalance() << endl; } // end function outputline // obtain account-number value user int getaccount( const char * const prompt ) { int accountnumber; // obtain account-number value { std::cout << prompt << " (1 - 100): "; std::cin >> accountnumber; } while ( accountnumber < 1 || accountnumber > 100 ); return accountnumber; } // end function getaccount
i have -----line 38 try , distinguish of other jumble.. have never received error before so, options trying fix limited. did try research error prior posting on here, nothing able explain solution.
i realize have variables going int void , void int. said, have tried making 1 or other, results in more compilation errors.
you meaning call function, not use function pointer. change line to:
while ( ( choice = enterchoice() ) != end )
but have enterchoice
declared return void
, makes statement not make sense. later on, in implementation, have declared return int
, need make prototype match that.
Comments
Post a Comment