does anyone have any advice? i created a program and it works fine.

my teacher, however, is asking me to have my INPUT and OUTPUT to be subprograms such as the VOID function.

i guess my algorithmn has to be..
// struct
// void for inputs
// void for printing
// my main

i have no idea how to go about on doing that.
ive created programs with void functions before, but its different, a lot different.
i tried making this program into a void, but i got a whole lot of errors.

anyone have any ideas or pointers? thanks

#include <iostream>
#include <string>
using namespace std;

//Structure 
struct student
{   
    int zip;
    int id;   
    float gpa;   
    string name;     
    string address;  
    string city;     
    string state;
    string gender;        
}stud[3]; //Array size


int main()
{
    cout<< "\n----------Enter Student Information---------\n";
    
    int i = 0;

    //for loop 
    for(i=0; i<3; i++)
    {
                 
         //Input 
         cout << "\nFirst name of student #" << ": ";
         getline(cin, stud[i].name);

         cout << "Address of student    #"   << ": ";
         getline(cin, stud[i].address);
           
         cout << "City of student       #"   << ": ";
         getline(cin, stud[i].city);
         
         cout << "State of student      #"   << ": ";
         getline(cin, stud[i].state);
         
         cout << "Zip code of student   #"   << ": ";
         cin >> stud[i].zip;
         cin.ignore(1000, 10);
          
         cout << "Student gender [M,F]  #"   << ": ";
         cin >> stud[i].gender;
         
         cout << "ID number of student  #"   << ": ";
         cin >> stud[i].id;
         cin.ignore(1000, 10);

         cout << "GPA of student        #"   << ": ";
         cin >> stud[i].gpa;
         cin.ignore(1000, 10);
    }

    cout<< "\n----------Student Information---------\n";
        
    for(i=0; i<3; i++)
    {

      //Output
      cout << "\nName of student     # " << i << ": " << stud[i].name;
      cout << "\nAddress of student  # " << i << ": " << stud[i].address;
      cout << "\nCity of student     # " << i << ": " << stud[i].city;
      cout << "\nState of student    # " << i << ": " << stud[i].state;
      cout << "\nZip code of student # " << i << ": " << stud[i].zip;
      cout << "\nGender of student   # " << i << ": " << stud[i].gender;
      cout << "\nID of student       # " << i << ": " << stud[i].id;
      cout << "\nAge of student      # " << i << ": " << stud[i].gpa<<"\n";
    
    }

  cin.ignore();
  cin.get();
  return 0;
}

I think this is kind of what you're looking for!

student stud[3];


for (i = 0; i < 3; i++)
   EnterRecord( &stud[i] );

void EnterRecord( student *pRec )
{
   // Put your data entry per record here!
}
for ....
{
   // code
   // code
   // code
}

Becomes

void func ( void ) {
   // code
   // code
   // code
}

for ....
{
    func();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.