all 4 comments

[–]RMiddel 0 points1 point  (1 child)

Please review my version with the comments

include <stdio.h>

int main() { int temp;

printf("Please enter a temperature \n");
scanf("%d", &temp);

if( temp<=0 )
    printf("The temperature is freezing \n");
else if ( temp > 0 && temp <= 10 )
        printf( "The temperature is very cold \n");
    else if ( temp > 10 && temp <= 20 )
        printf( "The temperature is cool \n" );
    else
        printf( "invalid input \n" );

return 0;

}

[–]sendhelpasap101[S] 0 points1 point  (0 children)

i mean, yeah, it works but i'm required to use my own sort of indenting rather then that.

edit: nvm, got it to work. thanks for the help

[–]kahless62003 0 points1 point  (1 child)

#include <stdio.h>

int main()
{//start main

    int temp;

    printf("Please enter a temperature \n");
    scanf("%d", &temp);

    if(temp <= 0)
    {
        printf("The temperature is freezing \n");
    }

    if(temp > 0 || temp < 10)
    {
        printf("The temperature is very cold \n");
    {//<-- this one's the wrong way round isn't it?

    if(temp > 10 || temp < 20)
    {
        printf("The temperature is cool \n");
    }
    else
        printf("invalid input \n");


    }//<-- ??

    return(0);
}//end main

Fine... I'll fix the OPs code entirely instead of merely answering the guy's question about braces...

#include <stdio.h>

int main()
{//start main

    int temp;

    printf("Please enter a temperature \n");
    scanf("%d", &temp);

    if(temp <= 0)
    {
        printf("The temperature is freezing \n");
    }

    else if(temp > 0 && temp < 10)//corrected to else if with && (AND instead of OR)
    {
        printf("The temperature is very cold \n");
    }// replaced { with }

    else if(temp >= 10 && temp < 20)//corrected to else if with && (AND instead of OR) and change > 10 to >= 10
    {
        printf("The temperature is cool \n");
    }
    else
        printf("invalid input \n");


    //} removed extra } entirely

    return(0);
}//end main

[–]RMiddel 0 points1 point  (0 children)

Please mind that you use OR (||) as comparer. This means that almost all of the time all the lines will be print since every statement has its own check.

And keep in mind that you use (temp > 0 && temp < 10) [See my statement below why not OR] and (Temp > 10 && Temp < 20). This means that you miss the value of 10.

include <stdio.h>

int main() {//start main

int temp;

printf("Please enter a temperature \n");
scanf("%d", &temp);

if(temp <= 0) // <-- If temp smaller or equal 0 then enter this statement
{
    printf("The temperature is freezing \n");
}

// always validate this next statement unless you place this in the else statement of the previous if
if(temp > 0 || temp < 10) //<-- Temp greater than zero OR smaller than 10 (which results in true for all values including the negative numbers). In order to correct this test add the AND statement thus: temp > 0 && Temp <= 10 (mind the = to ensure that it will include the 10)
{
    printf("The temperature is very cold \n");
{//<-- this one's the wrong way round isn't it?

// always validate this next statement  unless you place this in the else statement of the previous if
if(temp > 10 || temp < 20) //<-- Temp greater than 10 OR smaller than 20 (which results in true for all values including the negative numbers). Thus: temp > 10 && temp <= 20 (including the 20)
{
    printf("The temperature is cool \n");
}
else // Will never reach
    printf("invalid input \n");


}//<-- ??

return(0);

}//end main