Hi I am trying to make a nursery registration form for an assignment at uni and have hit a stumbling block. I have written the functions but dont really know what to declare them as. Could anyone help.

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
 int menu(); //creating a function called menu
  Enter_child_dets();
Enter_parent_dets();
 Display_child_dets();
 Search_parent(); 
 help();
int main(int argc, char *argv[])
{
    int users_choice; users_choice=menu();
    menu();
    switch (users_choice)

    {
    
               case 1://close will break automatically
                      break;
               case 2: Enter_child_dets();
                      break;
               case 3: Enter_parent_dets();
                      break;
               case 4: Display_child_dets();
                      break;
               case 5: Search_parent();
                      break;
               case 6: help();
                      break;
              default: cout<<"You made an invalid choice";
                  
    } 
    system("PAUSE");
    return EXIT_SUCCESS;
    //-----------------------------------------------------------------------------------------------------------------------
}

int menu()
     {
           int users_choice;
           cout<<"=====Nursery Registration System====="<<endl<<endl<<endl;
           cout<<"\t1 - Quit"<<endl;
           cout<<"\t2 - Enter Child Details"<<endl;
           cout<<"\t3 - Enter Parent Detals"<<endl;
           cout<<"\t4 - Display Children Details"<<endl;
           cout<<"\t5 - Search Parent"<<endl;
           cout<<"\t6 - Help Information"<<endl<<endl;
           cout<<"\tPlease make your choice: ";
           cin>>users_choice;//create a variable to send a value to users_choice
           return users_choice;//return choice
    }
//--------------------------------------------------------------------------------------------------------
 Enter_child_dets()//enter child name, enter child age, save it to a text file.
    {  
      {    
       string child_name;
       int child_age;
       child_name = child_name();
       child_age = child_age();
       save_child(child_name, child_age);
 
              
           
       }
         
       string child_name()
       {    
            string child_name; child_name="";
    do
           {
           
                   cout<<"Enter Name of Child: ";
                   cin>>child_name;
           }  
           while(child_name.length <1 || child_name.length >50)//length of name has to be be >1 or <50
           return child_name;        
        }
        int child_age();
        {
             int child_age
    do
           {
                    cout<<"Enter Age of Child: ";
                    cin>>child_age;
           }
           while (child_age <1 || child age > 5;
           return child_age;
        }
        save_child(string child_name, int child_age) //copying information from each variable as opposed to
        {
            ofstream myfile;
            myfile.open("child.txt", ios  ::app);
            myfile<<child_name<< " , "<<child_age<<endl;
            myfile.close;
        }
    }       
//-----------------------------------------------------------------------------------------------------------------
 Enter_parent_dets();//enter child name, enter child age, save it to a text file.
    {  
      {    
       string parents_name;
       int parents_tel;
       parents_name = parents_name();
       parents_tel = parents_tel();
       save_parent(parents_name, parents_tel);
 
              
           
       }
         
       string parents_namee()
       {    
            string parents_name; parents_name"";
    do
           {
           
                   cout<<"Enter Name of parent: ";
                   cin>>parents_name;
           }  
           while(parents_name.length <1 || parents_name.length >50)//length of name has to be be >1 or <50
           return parents_name;        
        }
        int parents_tel();
        {
             int parents_tel
    do
           {
                    cout<<"Enter Telephone Number: ";
                    cin>>parent_tel;
           }
           while (parents_tel <1 || parents_tel > 5;
           return parents_tel;
        }
        save_child(string parent_name, int parent_tel) //copying information from each variable as opposed to
        {
            ofstream myfile;
            myfile.open("guardian.txt", ios  ::app);
            myfile<<parent_name<< " , "<<parent_tel<<endl;
            myfile.close;
        }
    }
 //-------------------------------------------------------------------------------------------------------------
   Display_child_dets()
       {
      long begin,end;
  ifstream myfile ("child.txt");
  begin = myfile.tellg();
  myfile.seekg (0, ios::end);
  end = myfile.tellg();
  myfile.close();
  cout << "size is: " << (end-begin) << " bytes.\n";
  return Display_child_dets;
}
//----------------------------------------------------------------------------------------------
   Search_parent()
    {
    
            {
            int enter_id
            enter_id()=enter_id();
            find_parent(enter_id);
            }
        int enter_id
                {
                          cout<<"Enter childs ID";
                          cin>>enter_id;
                          return enter_id
                 } 
        find_parent(enter_id);
                 {
                              ifstream myfile("guardian.txt);
                              if myfile.is_open()
                              {
                                 while(!myfile.eof())
                                 {
                                   line_number++;
                                   getline(myfile, line);
                                   if(line_number==child_id){break;}
                                 }
                 if(line_numbre==child_id)
                    {
                      cout<<line<<endl;
                      myfile.close();
                    }
                    else cout<<"unable to read file";
                    else =||= 
                 }
                               
                 else cout<<"unable to read file";
        }
                    
                 
                 }     
                 
//------------------------------------------------------------------------------------------
     }
     void help()
     {
           cout << "                           Help                                  "<<endl;
            cout<<  "                           ----                                  "<<endl;
			cout << "\tTyping a number will have a specific outcome." << endl;
			cout << "\tTyping 1 quits the program, and 2 lets you enter a childs name" << endl;
			cout << "\tif you type 3, the program lets you enter the parents name." << endl;
			cout << "\twhere as 4 will display all the children" << endl;
			cout << "\t5 will let you search for the childs parent" <<endl;
			cout << "\tand 6 which you have already pressed opens up help" <<endl<<endl<<endl<<endl<<endl;
     }

which function do you mean? If you mean lines 6-10 then the those functions must be declared to return something, such as int function() or void something() . Default return values are not permitted in c++.

line 153: that should be () at the end because its calling a function. However, that aside, the line is making a recursive call because its calling itself, and that will crash your program because there is nothing in that function to stop the recursion.

Edited 6 Years Ago by Ancient Dragon: n/a

hi sorry for my lack of an explanation. I have to declare the functions named below globally
#
Enter_child_dets();
#
Enter_parent_dets();
#
Display_child_dets();
#
Search_parent();
#
help();

each function has been made up and some return values and others dont. THe problem is that I dont know whether they should be integers or chars or strings etc. THis being because some return text to main and others return nothing. I tried putting void above them all in main but it comes up with messages like

expected constructor, destructor, or type conversion before ';' token

i dont know what constructer types each function is. Sorry if its hard to understand.

The return type is the same type as what the function returns. Those that return nothing are declared void function(); . If the function returns an integer then declare it as int function(); That shouldn't be all that hard to figure out -- just look at the return statement in the function.

lines 5-10 are in the correct place, all you have to do is add the return type to those function prototypes.

lines 13 and 14: that is calling function menu() twice. Delete the function call on line 13 and make line 14 look like the function call that's on line 13.

Edited 6 Years Ago by Ancient Dragon: n/a

This question has already been answered. Start a new discussion instead.