c++ programming function error -
my full code (couldn't make smaller) :
/*password admin*/ #include <iostream> #include <fstream> #include <algorithm> #include <string> using namespace std; //------------------------------- fstream d_base; char path[] = "library books.txt"; void output(){ //this function displaying choices cout << "***********************************" << endl; cout << "1. list books in library" << endl; cout << "2. list available books borrow " << endl; cout << "3. borrow book library" << endl; cout << "4. search book" << endl; cout << "5. add new books"<< endl; cout << "6. delete book" << endl; cout << "7. exit library"<< endl; cout << "***********************************" << endl; } //===================================================================================================================================================== struct books{ //identfying books needed things int id, status; string title, p_name, p_address; string aut_name, aut_nationality; string date; }; //===================================================================================================================================================== //function choice 1 showing books (under constructions) void choice1(){ ifstream show; char all; show.open(path, ios::in | ios::app); while (!show.eof()){ show >> all; if (all == '%'){ cout << "\n\n"; } else if (all == '.'){ cout << "\n\n\n"; } else cout << all; } cout << endl; show.close(); } //===================================================================================================================================================== void choice2(){ //function choice 2 (list available books borrow) } //===================================================================================================================================================== void choice3(){ //function choice 3( borrow book ) } //===================================================================================================================================================== void choice4(){ char s; ifstream search; char idx; cout << "what book want search : "; cin >> idx; search.open(path, ios::in | ios::app); while (!search.eof()){ search >> s; if (s == idx) cout << "book found" << endl; break; } search.close(); } //===================================================================================================================================================== //for choice 5 fill books (under constructions) void choice5(books new_book[],books aut[], int books_number,int aut_number){ //function adding books system cout << "how many books want add ? "; cin >> books_number; //call function record book d_base.open(path, ios::out | ios::app); (int = 0; < books_number; i++){ d_base << "[book id]: " << new_book[i].id << "%[title]: " << new_book[i].title; d_base << "%[publisher name]: " << new_book[i].p_name << "% [puplisher address]: " << new_book[i].p_address; (int j = 0; j < aut_number; j++){ d_base << "%[author info]" << "%[authors name]: " << aut[i].aut_name << "%[nationality]: " << aut[i].aut_nationality; } d_base << "%[publishedat]: " << new_book[i].date << "%[status]:" << new_book[i].status << "." << endl; } d_base.close(); } //===================================================================================================================================================== void choice6(){ //function searching book } //===================================================================================================================================================== int main(){ string choice; cout << "welcome fcis library\n\n"; do{ output(); cout << "what want ? "; getline( cin , choice); if (choice == "1"){ choice1(); } //this 1 list available books else if (choice == "2"){ choice2(); } //this 1 borrow book else if (choice == "3"){ //not completed yet don't choose 3 } else if (choice == "4"){ choice4(); } //this 1 adding new books list else if (choice == "5"){ int books_number, aut_number; books new_book[10000], aut[10000]; string password; do{ cout << "you must admin add new books." << endl << "please enter passowrd (use small letters) : "; cin >> password; if (password == "b") break; else if (password == "admin"){ cout << "access gained welcome " << endl; cout << "what books want add :" << endl; (int = 0; < books_number; i++){ cout << "id please : "; cin >> new_book[i].id; cout << "title : "; cin.ignore(); getline(cin, new_book[i].title); cout << "publisher name :"; getline(cin, new_book[i].p_name); cout << "publisher address : "; getline(cin, new_book[i].p_address); cout << "publish date :"; getline(cin, new_book[i].date); cout << "how many copies of " << new_book[i].title << " "; cin >> new_book[i].status; cout << "how many authors book ?"; cin >> aut_number; (int j = 1; j <= aut_number; j++){ cout << "author number " << j << " name : "; cin.ignore(); getline(cin, aut[i].aut_name); cout << "nationality : "; getline(cin, aut[i].aut_nationality); choice5(new_book[i], aut[j], books_number, aut_number); } } } else{ cout << "wrong password try again or press (b) try choice"; continue; } } while (password != "admin"); } //this 1 deleteing book else if (choice == "6"){ //not completed yet } else if (choice == "7"){ cout << "thanks using fcis library" << endl; break; } else cout << "\nwrong choice please choose again\n\n"; } while (true); }
the problem when call choice5() function gets me errors :
*-intellisense: no suitable conversion function "books" "books
*-intellisense: no suitable conversion function "books" "books
-error c2664: 'void choice5(books [],books [],int,int)' : cannot convert argument 1 'books' 'books []
i don't know if it's parameters problem or what!!
the choice5(); function call in main in if(choice==5) after submitting books
and i'm level 1 @ c++ i'm doing best make smaller
i don't know if it's parameters problem or what!!
the compiler tells , problem is: call choice5
. first parameter array of books
, you're passing in single book
.
choice5(new_book[i], aut[j], books_number, aut_number);
new_book
array, new_book[i]
particular book
in array. same goes aut
.
Comments
Post a Comment