Dear all,
I have a prog working and printing to screen. But as my program has grown i.e class/method definitions I need to tidy up my main();
my problem is with printing my results to the screen.
///this will print out to screen perfectly. note i left out the class/method definitions as there are too many.
ANY IDEA WHY MY FUNCTIONS BELOW WILL NOT PRINT OUT DETAILS OF ARRAY TO SCREEN.
int main(int argc, char *argv[])
{
doctor* Array[5];
doctor* newdoctor;
int choice;
int i,age,hrs;
string names;
for(int i=0;i<3;i++)
{
cout<<"1.doctor, 2.Junior, 3.Consultant"<<endl;
cin>>choice;
if (choice==1)
newdoctor = new doctor();
else if (choice==2)
newdoctor = new junior();
else
newdoctor = new consultant();
cout<<"Enter doctor name"<<endl;
cin>>names;
newdoctor->set_Name(names);
cout<<"Enter doctor Age"<<endl;
cin>>age;
newdoctor->set_Age(age);
cout<<"Enter no of hrs worked"<<endl;
cin>>hrs;
newdoctor->set_Hours(hrs);
Array[i]=newdoctor;
}
cout<<"\n";
for(i=0;i<3;i++)
{
cout<<"Name: "<<Array[i]->get_Name();
cout<<"\n";
cout<<"Age: "<<Array[i]->get_Age();
cout<<"\n";
cout<<"Holiday Bonus: ";
Array[i]->get_holidaypay();
cout<<"\n";
cout<<"Total: "<<Array[i]->calculate_pay();
cout<<"\n";
cout<<"PayRate: "<<Array[i]->get_Payrate();
cout<<"\n";
delete Array[i];
}
system("PAUSE");
return 0;
}
HOWEVER
//when I try to clean-up main() & call my fuctions it will not print the details of the Array. before I started cleaning the prog the whole lot worked perfectly.
Do I need to pass the doctor Array[] to the void Print_Doctor_Details(); and if i do should void Enter_Doctor_Details(); pass back the array so i can pass it onto void Print_Doctor_Details();
void Enter_Doctor_Details();
void Print_Doctor_Details();
int main(int argc, char *argv[])
{
doctor* Array[5];
Enter_Doctor_Details(); //this function works
Print_Doctor_Details(); //having trouble getting this to work
system("PAUSE");
return 0;
}
void Enter_Doctor_Details()
{
doctor* newdoctor;
int choice;
string doctorname;
int i,doctorage,hrs;
doctor* Array[5];
for(int i=0;i<2;i++)
{
cout<<"1.doctor, 2.Junior, 3.Consultant"<<endl;
cin>>choice;
if (choice==1)
newdoctor = new doctor();
else if (choice==2)
newdoctor = new junior();
else
newdoctor = new consultant();
cout<<"Enter doctor name"<<endl;
cin>>doctorname;
newdoctor->set_Name(doctorname);
cout<<"Enter doctor Age"<<endl;
cin>>doctorage;
newdoctor->set_Age(doctorage);
cout<<"Enter no of hrs worked"<<endl;
cin>>hrs;
newdoctor->set_Hours(hrs);
Array[i]=newdoctor;
}
}
void Print_Doctor_Details()
{
doctor* Array[5];
for(int i=0;i<2;i++)
{
cout<<"Name: "<<Array[i]->get_Name();
cout<<"\n";
cout<<"Age: "<<Array[i]->get_Age();
cout<<"\n";
cout<<"Holiday Bonus: ";
Array[i]->get_holidaypay();
cout<<"\n";
cout<<"Total: "<<Array[i]->calculate_pay();
cout<<"\n";
cout<<"PayRate: "<<Array[i]->get_Payrate();
cout<<"\n";
delete Array[i];
}
}
<< moderator edit: removed garish colors and added [co[u][/u]de][/co[u][/u]de]
tags >>