i build this beginner code for my college project
and i had some errors
this a part of it:
# include <iostream>
# include <iomanip>
# include <string>
# include <fstream>
using namespace std;
void add_new_student(string Name[100],int Student_Number[100],long long int Mobile_Number[100],string Address[100],char Sex[100],string SNB[1000]);
void add_new_book(long long int ISBN_Number[1000],string Title[1000],int edition[1000],string author_name[1000],bool Borrowed_Or_Not[1000],string SNB[1000]);
void modify_student_info(string Name[100],int Student_Number[100],long long int Mobile_Number[100],string Address[100],char Sex[100],string SNB[1000]);
void modify_book_info(long long int ISBN_Number[1000],string Title[1000],int edition[1000],string author_name[1000],bool Borrowed_Or_Not[1000],string SNB[1000]);
void delete_student_info(string Name[100],int Student_Number[100],long long int Mobile_Number[100],string Address[100],string SNB[1000],char Sex[100]);
void delete_book_info(long long int ISBN_Number[1000],string Title[1000],int edition[1000],string author_name[1000],string SNB[1000], bool Borrowed_Or_Not);
void display_student_info(string Name[100],int Student_Number[100],long long int Mobile_Number[100],string Address[100],char Sex[100],string SNB[1000]);
void display_book_info(long long int ISBN_Number[1000],string Title[],int edition[1000],string author_name[1000],string SNB[1000],bool Borrowed_Or_Not);
void borrow_book(string Name[100],int Student_Number[100],long long int Mobile_Number[100],string Address[100],char Sex[100],long long int ISBN_Number[1000],string Title[1000],int edition[1000],string author_name[1000],bool Borrowed_Or_Not[1000],string SNB[1000]);
void store_list(string Name[100],int Student_Number[100],long long int Mobile_Number[100],string Address[100],char Sex[100],long long int ISBN_Number[1000],string Title[1000],int edition[1000],string author_name[1000],bool Borrowed_Or_Not[1000],string SNB[1000]);
void display_file_content();
int find (const string list[],int lingth,string search );
ofstream File_Content;
int NUM1,NUM2,NUM3,NUM4;
int main(){
int choice;
string Name[100],Address[100];
long long ISBN_Number[1000],Mobile_Number[100];
int Student_Number[100],edition[1000];
char Sex[100];
string Title[1000],author_name[1000],SNB[1000];
bool Borrowed_Or_Not[1000];
do{
cout <<"Choose a number and press enter: "<<endl
<<"1- Add a new student."<<endl
<<"2- Add a new book."<<endl
<<"3- Modify a specific student information."<<endl
<<"4- Modify a specific book information."<<endl
<<"5- Delete a specific student information."<<endl
<<"6- Delete a specific book information."<<endl
<<"7- Display a specific student information."<<endl
<<"8- Display a specific book information."<<endl
<<"9- Borrow a specific book."<<endl
<<"10- Store a list of all books borrowed by a specific student into a file."<<endl
<<"11- Display the content of the file."<<endl
<<"12- Exit"<<endl;
cin>>choice;
system("cls");
switch (choice){
case 1:add_new_student( Name, Student_Number, Mobile_Number, Address, Sex,SNB);break;
case 2:add_new_book( ISBN_Number , Title, edition ,author_name,Borrowed_Or_Not,SNB);break;
case 3:modify_student_info(Name, Student_Number, Mobile_Number, Address, Sex,SNB);break;
case 4:modify_book_info( ISBN_Number , Title, edition ,author_name,Borrowed_Or_Not,SNB);break;
case 5:delete_student_info(Name, Student_Number, Mobile_Number, Address,SNB,Sex);break;
case 6:delete_book_info( ISBN_Number , Title, edition ,author_name, SNB, Borrowed_Or_Not);break;
case 7:display_student_info(Name, Student_Number, Mobile_Number, Address, Sex,SNB);break;
case 8:display_book_info( ISBN_Number , Title, edition ,author_name,SNB, Borrowed_Or_Not);break;
case 9:borrow_book(Name, Student_Number, Mobile_Number, Address, Sex, ISBN_Number, Title, edition, author_name,Borrowed_Or_Not,SNB);break;
case 10:store_list (Name, Student_Number, Mobile_Number, Address, Sex, ISBN_Number, Title,edition, author_name, Borrowed_Or_Not,SNB);break;
case 11:display_file_content();
case 12: break;
default :cout << "Not a Valid Choice.\n"<< "Choose again.\n";cin>>choice;system("cls");break;}}
while (choice!=12);
return 0;
}
void add_new_student(string Name[100],int Student_Number[100],long long Mobile_Number[100],string Address[100],char Sex[100],string SNB[1000]){
char ch;
cout <<"Enter the number of students you want to add: ";
cin >>NUM1;
for (int i=0;i<NUM1;i++){
cout <<"Enter student's name (Include First name and Last name): ";
getline(cin, Name[i]);
cout << "Enter student's Sex(M or F): ";
cin >>Sex[i];
while (Sex[i]!='M'&&Sex[i]!='m'&&Sex[i]!='F'&&Sex[i]!='f'){
cout << "Invalid choice:\n"
<<"Enter student's Sex(M or F): ";
cin >> Sex[i];}
cout<<"Is the student borrowed a book(T/F): ";
cin>>ch;
while ((ch!='T')||(ch!='t')||(ch!='F')||(ch!='f')){
cout<<"Invalid Input.\n"
<<"The book is borrowed or not(T/F): ";}
if ((ch='T')||(ch='t'))
SNB[i]=Student_Number[i];
system ("pause");
system ("cls");
}}
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
You wrote:
i build this beginner code for my college project
and i had some errors
What errors and where? Post the actual error message. Explain what you are having a problem with.
As dhayden pointed out you are missing some functions. Hard to fine a problem if it should be in what is missing.
Try to avoid using global variables. Anything in the file can change them and then it is hard to track down.
1 2
ofstream File_Content; // <--- Should be in the function that needs it.
int NUM1, NUM2, NUM3, NUM4; // <--- Should be in "main" and passed to the functions that need them.