hey. can someone help me solve this?

Discussion in 'C' started by Masha, Mar 12, 2011.

  1. Masha

    Masha New Member

    Joined:
    Mar 12, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    every week from monday to friday you go to class. when it is raining, you take an umbrella.
    but on the weekend,what you do depends on the weather. if it is raining, you stay indoors. otherwise, you have fun outdoors.
    write a c program to present your weekly program using if/else control statements.
     
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    0
    Code:
    void whatToDo(int day, int raining)
    {
        // day: Monday = 1 .. Sunday = 7
        // raining: No = 0 , Yes = 1
    
        if (day <= 5)
        {
            printf("It's weekday - go to class.\n");
            if (raining)
    	{
    	    printf("It's raining - take an umbrella.\n");
    	}
    	else
    	{
    	    printf("It's sunny - no umbrella needed.\n");
    	}
        }
        else
        {
            printf("It's weekend - you have a free time.\n");
            if (raining)
            {
                printf("It's raining - stay at home.\n");
            }
            else
            {
                printf("It's sunny - have fun outside.\n");
            }
        }
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice