Question:

Help me regarding turbo c?

by  |  earlier

0 LIKES UnLike

help me please with this code my problem is if i enter 12 in month and 35 in day it will also says that you are capricorn how can i limit the day up to 31 only?

#include <stdio.h>

#define p printf

#define s scanf

main()

{

int month,day;

clrscr();

p("Enter Month of Birthday: ");

s("%d",&month);

p("Enter Day of Birthday: ");

s("%d",&day);

if(month==12 && day>=22)

{

p("You are Capricorn");

}

else if(month==1 && day<=19)

{

p("You are Capricorn");

}

getch();

return 0;

 Tags:

   Report

2 ANSWERS


  1. There is some modification reqd in ur program.

    Just wait for a few min...

    EDIT:

    Ok here it is-&gt;

    #include &lt;stdio.h&gt;

    #define p printf

    #define s scanf

    void main()

    {

    int month,day;

    clrscr();

    p(&quot;Enter Month of Birthday: &quot;);

    s(&quot;%d&quot;,&amp;month);

    p(&quot;Enter Day of Birthday: &quot;);

    s(&quot;%d&quot;,&amp;day);

    if(month==12&amp;&amp;(day&gt;=22&amp;&amp;day&lt;=31||....

    ...(month==1&amp;&amp;day&gt;=1&amp;&amp;&lt;=19))

    {

    p(&quot;You are Capricorn&quot;);

    }

    else

    p(&quot;You are not a Capricorn&quot;);

    }

    getch();

    }

    See, u had given only one condition of days greater than 22 but it should also have the limit of 31.

    Similarly, if u enter a negative number as a date for month January, then also it would give u output as Capricorn. So, I have made the condition as day&gt;=1 there.

    And u can see that I have clubbed the two conditions in one with an OR(||) statement to reduce the program size.

    Hope I helped!!!


  2. try this

    #include &lt;stdio.h&gt;

    #include &lt;stdlib.h&gt;

    #define p printf

    #define s scanf

    int main()

    {

    int month,day;

    p(&quot;Enter Month of Birthday: &quot;);

    s(&quot;%d&quot;,&amp;month);

    p(&quot;Enter Day of Birthday: &quot;);

    s(&quot;%d&quot;,&amp;day);

    if(month==12 &amp;&amp; (day&gt;=22 &amp;&amp; day &lt;=31))

    {

    p(&quot;You are Capricorn&quot;);

    }

    if(month==1 &amp;&amp; day&lt;=19)

    {

    p(&quot;You are Capricorn&quot;);

    }

    getch();

    return 0;

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.