Author Topic: Code blocks is going ballistic on me.  (Read 4643 times)

Offline kagenlim

  • Single posting newcomer
  • *
  • Posts: 3
Code blocks is going ballistic on me.
« on: August 16, 2017, 04:36:52 pm »
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;

        }
      }

   }


Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Code blocks is going ballistic on me.
« Reply #1 on: August 16, 2017, 06:42:54 pm »
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?

Offline kagenlim

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code blocks is going ballistic on me.
« Reply #2 on: August 17, 2017, 08:38:03 am »
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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Code blocks is going ballistic on me.
« Reply #3 on: August 17, 2017, 01:32:22 pm »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline kagenlim

  • Single posting newcomer
  • *
  • Posts: 3
Re: Code blocks is going ballistic on me.
« Reply #4 on: August 18, 2017, 04:55:05 am »
just great.thanks for your help.Not.

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Code blocks is going ballistic on me.
« Reply #5 on: August 18, 2017, 07:08:31 am »
Apparently reading is not your strength, now this is rude and useless...

But maybe its just my eyes, so please help me, what problem exactly is CodeBlocks giving you? Because all i saw so far is that you seem to have a program you can start, so its looks like CodeBlocks could run your compiler to compile your code and even execute the produced binary. So really, whats not working with your CodeBlocks?!

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Code blocks is going ballistic on me.
« Reply #6 on: August 18, 2017, 08:39:37 am »
Please follow the rules as mentioned before.
Topic locked!