Saturday 28 July 2012

Conditional statement018


A certain grade of steel is graded according to the following condition:
1)      Hardness must be greater than 50
2)      Carbon content must be less than 0.7
3)      Tensile strength must be greater than 5600

The grades are as follows:
§  Grade is 10 if all three conditions are met
§  Grade is 9 if conditions (1) and (2) are met
§  Grade is 8 if conditions (2) and (3) are met
§  Grade is 7 if conditions (1) and (3) are met
§  Grade is 6 if only one conditions is met
§  Grade is 5 if none of the conditions are met

Write a program which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.

#include <stdio.h>
#include <conio.h>
void main ( )
{       
        float        hard, c, tens;
        clrscr ( );
                        
        printf ("\n\n\n\t\t Enter the hardness of steel .......:"); scanf ("%f", &hard);
        printf ("\n\t\t Enter the carbon content of steel ...:"); scanf ("%f", &c);
        printf ("\n\t\t Enter the tensile strength of steel ..:"); scanf ("%f", &tens);
        
        if ( hard > 50 && c < 0.7 && tens > 5600)
        {                          
                    printf ("\n\n\n\n\t\t\t GRADE 10");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }           
        if ( hard > 50 && c < 0.7 && tens < 5600)
        {                                        
                    printf ("\n\n\n\n\t\t\t GRADE 9");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }                            
        if ( hard <= 50 && c < 0.7 && tens > 5600)
        {                          
                    printf ("\n\n\n\n\t\t\t GRADE 8");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }                                    
        if ( hard > 50 && c >= 0.7 && tens > 5600)
        {                           
                    printf ("\n\n\n\n\t\t GRADE 7");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }                                 
        if ( hard > 50 || c < 0.7 || tens > 5600)
        {                                
                    printf ("\n\n\n\n\t\t GRADE 6");
                    printf ("\n\n\n\n Press any key to exit");
                    getch ( );
                    exit ( );                /* Terminates the execution */
        }
        printf ("\n\n\n\n\t\t GRADE 5");
        printf ("\n\n\n\n Press any key to exit");
        getch( );
}

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...