|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hello!
I'm currently working on a project and I'm having a bit of an hard time with two functions in specific: Function 1:In this function I want the doctor's number of patients to increase after patient has consulted that doctor. As so,by means of testing the function,in the menu, I add a doctor to the array of doctors and then I add a patient.In the patient fields that are asked in program(name,age,address), I fill the field name of the doctor with the doctor that treated/will treat him. After that,I check the doctor's data and the number of patients has indeed increased by one. Problem: If I add another doctor and add another patient,and in the patient's doctor name field I add the new doctor name,in the doctor's data,instead of just incrmenting the new doctor's patient it increments the new doctor's patient and the other doctor! Code: Code:
void addpatients_to_doctors(Doctors array_of_doctors[],Patients array_of_patients[],int ndoctors,int npatients)
{
int i,z,count=0,x;
for(i=0;i<ndoctors;i++) // Goes through array of doctors
{
for(x=0;x<npatients;x++) // Goes through array of patients
{
for(z=0;z<array_of_patients[x].nconsultations;z++) // Goes through number of existing consultations
{
if(strcmp(array_of_doctors[i].p.name, array_of_patients[x].h[z].doctorname)==0) //compares the name in the doctor's file with the name of the doctor in the patient's historic consultations
count++;
}
if(count==1)
array_of_doctors[i].npatients++;
count=0;
}
}
}
Function 2:In this function I want the patient's historic to have at a maximum 10 consultations from the oldest in the beggining of the array to the newest. After reaching the 10 consultations, the consultation on pos 1 of array will be copied to pos 0,the consultation from pos 2 to pos 1 and from that forward until it reach the last pos where it will have "today's" consultation. Problem: This all works alright after I reach the 10 consultations.After that it looks like all the historic is erased and it copies the newwest consultation to teh beggining having only that input on the historic. Code:
int keep_data_con(Patients array_of_patients[],Doctors array_of_doctors[],int npatients)
{
int i,z,nconsultations;
char nid[12];
printf("Input your id:\n");
gets(nid);
for(i=0;i<npatients && strcmp(nid,array_of_patients[i].p.npid)!=0; i++);
if(i==n)
{
printf("Patient doesn't exist\n");
return 0;
}
else
{
nconsultations=array_of_patients[i].numconsultations++;
if(nconsultations==10)
{
for(z=0;z<nconsultations;z++)
array_of_patients[i].h[z]=array_of_patients[i].h[z+1];
array_of_patients[i].h[numconsultations-1]=get_data_conultations(array_of_doctors,npatients);
}
else
array_of_patients[i].h[numc]=get_data_consultations(array_of_doctors,npatients);
}
}
|
| Sponsored Links |
|
|
|
|||||
|
Maybe it's just me, but not having all the classes/structs defined in your code is making it harder to determine what your code is trying to do. What is Patients and Doctors?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array manipulation Question in C++ | JJJIrish05 | C and C++ | 1 | 03-08-2008 02:06 PM |
| Problems passing a serialized array in a session variable | gszauer | PHP Forum | 3 | 02-15-2008 11:18 AM |
| Usage of array structures to increment letter instances of text | Yuriy M | C and C++ | 2 | 09-13-2007 10:49 AM |
| fread into array position | kenna | C and C++ | 0 | 08-17-2007 08:03 AM |
| Python 2D array question | annannienann | Python | 3 | 04-23-2007 04:36 PM |
Goal: 100,000 Posts
Complete: 68%