how to return in void function();

This is a discussion on how to return in void function(); within the C++ Programming forums, part of the General Programming Boards category; i want to return begining in void function(); like return in main(); if is wrong number i want to ask ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    24

    Arrow how to return in void function();

    i want to return begining in void function(); like return in main();
    if is wrong number i want to ask till number right.
    but my codes returning the main all the time i tryid
    return;
    but still same. does anybody know how kan i return????

    Code:
    void function( )
    {
        cout<<"WHAT IS THE NUMBER:";
        cin>>number;
        cin.get();
    
          for(int i=0; i<Size; i++)
             {
               if (NUMBER RIGHT)
                   {
                      cout<<"\NUMBER RIHGT"<<endl;
                      cin.get();
                      break;
                    }
              }
               if(NUMBER WRONG)
                    {
                      cout<<"\WRONG NUMBER TRY AGAIN";
                      cin.get();
                     }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,975
    You should name your function with a more descriptive name.

    Anyway, it looks like what you want to do is to structure your loop such that you keep on requesting for input until the correct number is entered.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    24
    here is my real codes, if entry date and time not in the array i want to ask again till its find in array
    so how im gonna do it????
    Code:
    void deleteAppointmentRecords( )
    {
        bool flag = false;
    	string deleteTime;
        int deleteday,deletemounth,deleteyear;
        int update;
        system("cls");  //clear screen
        cout<<"\nEnter Appointment Date you want to Delete: ";
        cin>>deleteday>>deletemounth>>deleteyear;
        cin.get();
        cout<<"\nEnter Appointment Time you want to Delete: ";
        cin>>deleteTime;
        cin.get();
        for(int i=0; i<currentSize; i++)
    	{
    	    if (AppointmentList[i].appdate.day == deleteday && 
    	        AppointmentList[i].appdate.mounth == deletemounth && 
    	        AppointmentList[i].appdate.year == deleteyear && 
    	        AppointmentList[i].time == deleteTime)
    			 {
    			        update = i;
    				system("cls");  //clear screen
    			        displayHeading( ); //display Appointment under heading
    				cout<<setw(20)<<AppointmentList[update].name;	
    				cout<<setw(23)<<AppointmentList[update].description;
    				cout<<AppointmentList[i].appdate.day;
    				cout<<"/"<<AppointmentList[update].appdate.mounth;
    				cout<<"/"<<setw(14)<<AppointmentList[update].appdate.year;
    				cout<<AppointmentList[update].time;
    				cout<<endl; //indicate user Appointmen will be Delete
    				cout<<"\n\nAppointmen Above will be Delete!!!\n"<<endl;
    				cout<<"\nPress any key to continue"<<endl;
    				cin.get();
                                                   //delete Appointmen.
    				for(int k=update; k<=currentSize; k++)		   
    				AppointmentList[k] = AppointmentList[k + 1];
    
    				cout<<"\nAppointment Deleted!!!\n"<<endl;
    				cin.get();
    				flag = true;
    				currentSize -= 1; //update CurrentSize
    				break;
    		    }
    	}
    		if(!flag)
    		  {
    		     cout<<"\n\nThere is No Appointment on this Date and Time!!!\n";
    		     cout<<"\nEnter new Date and Time"<<endl;
    		     cin.get();
    		  }
    }

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,975
    Quote Originally Posted by pczafer
    if entry date and time not in the array i want to ask again till its find in array
    so how im gonna do it?
    Write a function that finds an appointment in the array given a date and time. This function should either return the index of the appointment in the array, or say, currentSize if it is not found.

    This way, your deleteAppointmentRecords can call this function. If the index returned is not currentSize, it would then call another function to delete the appointment by index. Otherwise, it would inform the user that no appointment exists at the given date and time, and thus request that the user input another date and time.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,975
    Quote Originally Posted by pczafer
    if entry date and time not in the array i want to ask again till its find in array
    so how im gonna do it?
    Write a function that finds an appointment in the array given a date and time. This function should either return the index of the appointment in the array, or say, currentSize if it is not found.

    This way, your deleteAppointmentRecords can call this function. If the index returned is not currentSize, it would then call another function to delete the appointment by index. Otherwise, it would inform the user that no appointment exists at the given date and time, and thus request that the user input another date and time.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    22
    If it is an integer you want to return, then change the void to int. Change the data type of the function declaration.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21