User forums > Help

Code blocks is going ballistic on me.

(1/2) > >>

kagenlim:
So i had to code for my school project.And the code seems splendid.Only problem is,that it has a crazy time on case 2.
heres the code btw.
Thanks in advance guys

--- Code: ---#include <stdio.h>
#include <stdlib.h>

int main()
{

    int i=0,count = 0,num_ppl = 0,choice = 0,num,year[4],day[2],month[2],contact_num,outer,count_undwght = 0,count_norwght = 0,count_ovrwght = 0,count_obsewght = 0,count_highbld = 0,count_lowbld = 0,count_norbld = 0;
    int USERID[100],newuser,Systolic,Diastolic;
    char name[30],gender;
    float Height,Weight,BMI;
  while(choice == 0)
  {
     printf("\n----------------------------------------");
    printf("\nMercy Health Screening System");
    printf("\n--------------------------------------");
    printf("\n\n\tRegistration-----------(1)");
    printf("\n\n\tHealth Screening-------(2)");
    printf("\n\n\tView Report------------(3)");
    printf("\n\n\tSurvey Report----------(4)");
    printf("\n\n\tQuit-------------------(5)");
    printf("\n\n--------------------------------------");
    printf("\nPlease Enter Your Choice:\t",num);
    scanf("%d",&num);

    switch (num)
    {
        case 1 :
       for  (i = 0;i <= 2;i++)
        {
         printf("\n-------------------------------");
         printf("\nClient Registration");
         printf("\n-------------------------------");

         printf("\n\nEnter your ID:");
         scanf("%d",&USERID[count]);


         printf("\n\nYour name?:");
         scanf(" %s",&name);


         printf("\n\nYour Birthday: dd/mm/yyyy:");
         scanf("%s/%s/%s",&day,&month,&year);


         printf("\n\nYour Contact Number?:");
         scanf(" %d",&contact_num);

         printf("\n\nYour gender? <M/F>:");
         scanf(" %c",&gender);

         num_ppl++;
        }

        break;


        case 2 :

        printf("\n-------------------------------");
        printf("\nHealth Screening");
        printf("\n-------------------------------");

        printf("\n\nEnter your ID:");
        scanf("%d",&newuser);

        for  (i = 0;i <= 2;i++)
        {

          if (newuser != USERID[i] && i == 2)
         {
            printf("\n%d has not been registered before",newuser);
            printf("\n----------------------------------------");

         }
         else if (newuser == USERID[i])
         {
         printf("\n\nYour height <m>?:");
         scanf(" %f",&Height);


         printf("\n\nYour weight<kg>?:");
         scanf("%f",&Weight);


         printf("\n\nYour Systolic pressure?:");
         scanf(" %d",&Systolic);

         printf("\n\nYour Diastolic Pressure?:");
         scanf(" %d",&Diastolic);
         }

       }
       
       break;

      case 3:
        printf("\n---------------------------------------------------------");
        printf("\nHealth report");
        printf("\n---------------------------------------------------------");
        printf("\nName:%c\t\t\t\tID:%d",name[30],USERID[100]);
        printf("\nGender:%c\t\t\tTel:%d",gender,contact_num);
        printf("\nWeight <kg>:%.2f\tHeight <m>:%.2f",Weight,Height);
        printf("\nBP Systolic:%d\tBP Diastolic:%d",Systolic,Diastolic);
        printf("\n---------------------------------------------------------");
        //Caculatin'
        BMI = Weight/(Height * Height);
        if (BMI < 18.5)
        {
            printf("\n<1>You are Underweight");
            count_undwght++;
        }
        else if (BMI >18.5 && BMI <24.9)
        {
            printf("\n<1>You are normal");
            count_norwght++;
        }
        else if (BMI> 25 && BMI < 29.9)
        {
            printf("\n<1>You are overweight");
            count_ovrwght++;
        }
        else
        {
            printf("\n<1>You are obese");
            count_obsewght++;
        }

        if (Systolic >=150 || Diastolic >= 100)
        {
            printf("\n<2>Your blood pressure is high");
            count_highbld++;
            printf("\n<3>Please see a doctor as soon as possible");
        }
        else if (Systolic <=80 || Diastolic <= 50)
        {
            printf("\n<2>Your blood pressure is low");
            count_lowbld++;
            printf("\n<3>Please see a doctor as soon as possible");
        }
        else
        {
            printf("\n<2>Your blood pressure is normal");
            count_norbld++;
            printf("\n<3>You're fine.Keep Going!");
        }

        break;

        case 4:
            printf("\n-------------------------------------");
            printf("\nHealth report");
            printf("\n-------------------------------------");
            printf("\nAmong %d people screened,there are :",num_ppl);
            printf("\n-------------------------------------");
            printf("\nHigh Blood Pressure : %d",count_highbld);
            printf("\nLow Blood Pressure : %d",count_lowbld);
            printf("\nNormal Blood Pressure : %d",count_norbld);
            printf("\nObese : %d",count_obsewght);
            printf("\nOver Weight : %d",count_ovrwght);
            printf("\nNormal Weight : %d",count_norwght);
            printf("\nUnder Weight : %d",count_undwght);
            printf("\n-------------------------------------");
            break;
        case 5 :
            printf("\n------------------------------------------------------------");
            printf("\nMercy Health Screening System");
            printf("\n------------------------------------------------------------");
            printf("\nThank you very much for using Mercy Health Screening System!");
            printf("\n\t\t\t\tGoodbye!");
            printf("\n------------------------------------------------------------");
            break;
            return 0;

        }
      }

   }


--- End code ---

sodev:
Play less Overwatch, write better code and post in the proper forum!

You dont have a CodeBlocks problem, you have coding problem. This is not a coding forum, dont post your coding problems here, only CodeBlocks problems!

Go to a beginner forum, you dont seem to understand how loops and arrays work. Why else do you reserve space for 100 users, never initialize the array which causes undefined behavior, only and always register 3 users at once and store all in the same position overwriting each other?

kagenlim:
Because this program was meant for 100 people.I changed it ot 3 so itll be easier to test.This is an otherwise rude and useless reply on your part

stahta01:
Read the rules!
http://forums.codeblocks.org/index.php/topic,9996.0.html

kagenlim:
just great.thanks for your help.Not.

Navigation

[0] Message Index

[#] Next page

Go to full version