Thread: New , Please help me .

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    10

    New , Please help me .

    1.//void medTest(int pulse, int age)
    // 35>age>0 - 40<pulse<120
    // 55>= age >= 35 - 40<pulse<110
    // age>55 - 40<pulse<100

    can some one help me understand how to make this function to work with if,else? kinda stuck :/ .

    2.

    i need to make this function to work like the Watch AP:PM , but i some how need to "%" so there is no able to be option that will output something like 23:60 and its just turn again to 00:00 and then start over 00:01am (12:01am) ..

    Code:
    void amPm(float time)
    {
        if (time>0&&time<=12)
        {
            printf("Am\n");
        }
        else if (time>12 && time<24)
        {
        printf("Pm\n");
        }
    }

    thank you very much to helpers.. if some one need better explain i will try .. if you will answer first here . have a good day!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,631
    > // 35>age>0 - 40<pulse<120
    So what do you want to do here?
    If the age is between those ages, check the pulse is between those limits?
    What if the pulse isn't between those limits, then what?

    if ( age > 0 && age < 35 )
    That's how the syntax works.

    > but i some how need to "%" so there is no able to be option that will output something like 23:60
    > and its just turn again to 00:00 and then start over 00:01am (12:01am) ..
    Well you need to first figure out what your 'time' parameter is counting - is it seconds?
    If so, seconds since when?

    Also, if you want to use the modulo operator (%), then time needs to be an integer, not a float.
    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
    Jul 2018
    Posts
    10
    Quote Originally Posted by Salem View Post
    > // 35>age>0 - 40<pulse<120
    So what do you want to do here?
    If the age is between those ages, check the pulse is between those limits?
    What if the pulse isn't between those limits, then what?

    if ( age > 0 && age < 35 )
    That's how the syntax works.

    > but i some how need to "%" so there is no able to be option that will output something like 23:60
    > and its just turn again to 00:00 and then start over 00:01am (12:01am) ..
    Well you need to first figure out what your 'time' parameter is counting - is it seconds?
    If so, seconds since when?

    Also, if you want to use the modulo operator (%), then time needs to be an integer, not a float.
    My parmaeter "time" should show the hour i put when i called it from main. time(12.30) for example.. So it will be 12:30 pm.
    I need to work with if else if to make this function to count from 00:00 to 23:59 . And then "/" module so bo option to get out side of the 60 min count every our . Example you cannot put 23:69 its wont print it. Cause its not an hour . Some how need to make this to work not sure how to do it .

    2 . If the age is between 0-35 and pulse is between 40-120 then print "Test Passed."
    Then if it between 35 and or equal to 55 , and pulse between 40-110 print "Test Passed"
    Then if 55>age and pulse some where between 40-100 its prints "Test Passed"
    If its not true on one of the "ifs" then prine Test Failed. Hope you understood now .

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,631
    Well it seems you know most of what needs to be done, give it a go.

    Perhaps this will be useful.
    modf(3) - Linux man page
    Given 12.3, it will allow you to extract 12.0 and 0.3 as separate floating point variables.
    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.

  5. #5
    Registered User
    Join Date
    Jul 2018
    Posts
    10
    Quote Originally Posted by Salem View Post
    Well it seems you know most of what needs to be done, give it a go.

    Perhaps this will be useful.
    modf(3) - Linux man page
    Given 12.3, it will allow you to extract 12.0 and 0.3 as separate floating point variables.

    Code:
    void medTest(int age, int pulse){
        if ((35>age&&age>0) && (pulse>40&&pulse<120))
        {
            printf("Test passed .");
        }
        else if((55>=age&&age>=35) && (40<pulse&&pulse<110))
        {
            printf("Test Passed .");
        }
        else if ((age>55) && (40<pulse&&pulse<100))
        {
            printf("Test Passed .");
        }
        else
        {
            printf("Test Failed.");
        }
    }
    i guess its ok now ,

    about the amPM i think i wasnt so clear.. , i need to make that the higher timer will show by 59. so i need to "mine time * 100" then %100 result should be no more then 59 .

    i dont understood how to do that into the function :\ thats mine problem .

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    36,631
    0.3 * 100 is 30

    Unless you're now saying that 12.99 (decimal hours) needs to be converted to 12.59 (hours.minutes).

    Either way, you begin with modf to extract the fraction, then you can scale it however you want.
    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.

Popular pages Recent additions subscribe to a feed

Tags for this Thread