Patient Structure Program - Help?

This is a discussion on Patient Structure Program - Help? within the C++ Programming forums, part of the General Programming Boards category; Could someone please look at this and tell me why it won't run? Code: #include <stdio.h> #include <stdlib.h> struct patient ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    2

    Unhappy Patient Structure Program - Help?

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

    Code:
    #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");
    
      if(i!=0)
        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++)
      {
        cholesterol_level=(a[x].ldl/a[x].hdl);
    
     }
    }
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2
    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
    Location
    Canada
    Posts
    8,046
    I don't think this does what you want it to do; see the FAQ titled "How do I . . . Clear the input buffer".
    Code:
    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>.
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    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, 06:49 PM
  2. program freezes - structure searching.
    By Vber in forum C Programming
    Replies: 9
    Last Post: 03-20-2003, 08: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, 08:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21