Thread: Patient Structure Program - Help?

  1. #1
    Registered User
    Join Date
    Oct 2006

    Unhappy Patient Structure Program - Help?

    Could someone please look at this and tell me why it won't run?

    #include <stdio.h>
    #include <stdlib.h>
    struct patient
    char id [20];
    int systolic;
    int diastolic;
    int ldl;
    int hdl;
    void main()
    int cholesterol_level;
     int i;
     struct patient a[4];
     for (i=0; i<=3; i++)
      printf("Please enter patient ID number \n");
        scanf("\n"); /*Clears memory buffer*/
    gets (a[i].id);
      printf("Please enter systolic blood pressure \n");
      scanf ("%d", a[i].systolic);
      printf("Please enter diastolic blood pressure \n");
      scanf ("%d", a[i].diastolic);
      printf ("Please enter ldl cholesterol \n");
      scanf ("%d", a[i].ldl);
      printf ("Please enter hdl cholesterol \n");
      scanf ("%d", a[i].hdl);
     int x;
    for(x=0; x<=3; x++)
    This is what it's supposed to do.

    You will define a patient structure for a patient checkup. The patient will have an id (letters and numbers), systolic blood pressure, diastolic blood pressure, ldl cholesterol, and hdl cholesterol. Check the input for the proper field types and sizes.

    In main, you will declare an array of 4 patients. You will be using a for loop to fill up the array of patients. Again, check input format. The user will be prompted and will input each of the fields.

    After a few new lines, you will print out the list of patients. At the top of the output, print a centered title Patient's Report, a blank line, and the column headings – Patient ID, Blood Pressure, and Cholesterol Ratio. Then with another for loop, print the patient id field, the blood pressure - systolic/diastolic (with the slash), and cholesterol ratio (ldl divided by hdl) with 2 decimal places. Make sure they print centered under the column headings by using field widths, precisions, alignments, etc.
    Last edited by Help_me0318; 10-18-2006 at 02:47 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > void main()
    This is in the FAQ (hint - watch the avatar)

    > gets (a[i].id);
    This is really bad - it's in the FAQ as well.

    > scanf ("%d", a[i].diastolic);
    You forgot all the & when using scanf, like
    scanf ("%d", &a[i].diastolic);
    scanf() is pretty poor as well.

    > int x;
    Apart from this declaration, there is no reason why this shouldn't be a C program.
    Are you learning C or C++?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2006
    I'm learned c last semester and I'm learning more c now. We also use a litlle c++, but not in this case.
    Last edited by Help_me0318; 10-18-2006 at 03:03 PM.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    I don't think this does what you want it to do; see the FAQ titled "How do I . . . Clear the input buffer".
    scanf("\n"); /*Clears memory buffer*/
    If that's supposed to be a C++ program, then you should be using cin instead of scanf, cout instead of printf, getline instead of gets (not that you should be using gets anyway), etc.

    with 2 decimal places
    In C, of course, you use a printf format specifier like %.2f; in C++, try the functions in <iomanip>.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 07:49 PM
  2. program freezes - structure searching.
    By Vber in forum C Programming
    Replies: 9
    Last Post: 03-20-2003, 09:35 AM
  3. Simple program structure.
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 05-15-2002, 04:36 AM
  4. binary tree node structure
    By Kirsten in forum C Programming
    Replies: 2
    Last Post: 04-26-2002, 08:02 PM
  5. structure program
    By prlove71 in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2002, 09:01 PM