Steel Grade C Program

Steel Grade System
Image result for c code

A certain grade of steel is graded according to the following conditions:
i. Hardness must be greater than 50.
ii. Carbon content must be less than 0.7.
iii. Tensile strength must be greater than 5600.

The grades are as follows:
a. Grade is 10 if all three conditions are met.
b. Grade is 9 if conditions (i) and (ii) are met.
c. Grade is 8 if conditions (ii) and (iii) are met.
d. Grade is 7 if conditions (i) and (iii) are met.
e. Garde is 6 if only one condition is met.
f. Grade is 5 if none of three conditions are met.

The Quality of the Steel is classified as follows:
1. Quality is "Very Good" if the grade of the steel is in more than 8.
2. Quality is  "Good" if the grade of the steel is the range of 6 to 8.
3. Quality is "Bad"  if the grade of the steel is in 5.

Write a program to display the grade of the steel along with its quality if  values of hardness, carbon content and tensile strength of the steel are given as inputs.

Business rules:
1. The value of the hardness,and tensile strength should be within the range 1 to 10000. If not, display the message "Invalid data either in hardness or tensile strength".
2. The value of the Carbon content should be within 0 to 1. If not, display the message "Invalid Carbon content".

Sample Input 1:
53
0.6
5602

Sample Output 1:
The Steel is Very Good with grade as 10

Sample Input 2:
10005
0.6
5602

Sample Output 2:
Invalid data either in hardness or tensile strength

The Method and inputs are:
void CalculateStreelGrade(int  input1, float input2, int input3)

Code: 
include<stdio.h> 
#include<conio.h> 

void main() 
int grade,hardness,tensile; 
float carbon; 
clrscr(); 

printf("\n Enter hardness: "); 
scanf("%d",&hardness); 

printf("\n Enter carbon content: "); 
scanf("%f",&carbon); 

printf("\n Enter tensile strength: "); 
scanf("%d",&tensile); 

if(hardness>50 && carbon<0.7 && tensile>5600) 
grade=10; 
else if(hardness>50) 
if(carbon<0.7) grade=9; 
else if(tensile>5600) grade=7; 
else grade=6; 
else if(carbon<0.7&&tensile>5600) 
grade=8; 
else if(carbon<0.7||tensile>5600) 
grade=6; 
else grade=5; 

printf("\n\n\n Grade: %d",grade); 
getch(); 
}

No comments: