Jump to content

Whats my mistake

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts
Whys is my snipplet code below only outputting one customer information


 


....................


strcpy(doctor2,"Dr.James.Brown");        

                  

                                        while(!feof(customer1)  && Found==0)

                                        {

                                                

                                                fscanf(customer1,"%s %s %s %s %s %d %d %d %d %d",det.name,det.regis,det.pname,det.treatment,det.piont,&det.fees,&det.collect,&det.insure,&det.balance,&det.value);

                        

                                                if(strcmp(doctor2,det.name)==0)

                                                {

                                                Found=1;

                        

                                                 count++;

                                                 fees = det.fees + fees;

                                                 collected = det.collect + collected;

                                                 

                                                 printf("\n\t\t  NAME:%s",det.pname);

                                                 printf("\n\t\t  TREATMENT:%s",det.treatment);

                                                 }           

                         

                                                 }

                     

                                                  if(Found)

                                                  {                                              

                                                     

                                                    printf("\n\t\t  DOCTORS NAME:%s",doctor2); 

                                                    printf("\n\t\t  NUMBER OF PATIENTS:%d",count);

                                                    printf("\n\t\t  TOTAL FEE CHARGED:$ %d",fees);

                                                    printf("\n\t\t  AMOUNT PAID:$ %d",det.collect);

                                                    printf("\n\t\t  FEES COLLECTED:$ %d",collected); 

                                                    printf("\n");

                                                    }

                        

                                                      else 

                                                       if(!Found)

                                                        printf("\n\n\t\t THERES NO SUCH RECORD");

                                                         }    

        

                       

                                                          Sleep(1000);

                                                          printf("\n\n\t\t\t  PRESS ENTER");

                                                          getch();

                                                          system("cls");

                                                          doctorrecord();                                        

                                                          break;

Example of file

Dr.John.Whyte 1001 Donellie.Whyte Filling 04/06/10 12000 5000 0 -7000 6

Dr.John.Whyte 1002 James.Cameron Extraction 04/10/09 12000 6000 0 -6000 7

Dr.John.Whyte 1003 Kameron.Ellis Extraction 29/08/10 12000 12000 0 0 36



#2
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
The while statement at the top says to continue as long as variable Found is 0. After the fscanf() it checks if the doctor's name is the one it is looking for. If it is, then it sets Found to 1. That will make the entire while loop stop.

If you want to read all the records for that doctor, then you need a little more checks. After the first record for the doctor is read, the program needs to continue reading records until the doctors name changes to something else. Something like this pseudocode

start of infinite loop
    read a record
    does it contain the doctor's name that we want
    no, then  go back to top of infinite loop
    while doctor's name is the one we want
        print data
        read another record
    end while
end infinite loop

Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.