In: Computer Science
IN C LANGUAGE
You decide you want to build a skate park in your backyard, so you need to buy a lot of concrete. The good news is, you can get a discount when you buy in bulk. The price of concrete for different grades of concrete per cubic yard is as follows:
Write a program that calculates the price of an order of concrete when given the grade and quantity.
Notes
Examples
What grade of concrete (low/cheap, high/expensive)? low How many cubic yards of concrete? 75 The cost is $7500
The answer to the example above is calculated from 75 * $100 (low grade, less than 200 cubic yards) = $7500
What grade of concrete (low/cheap, high/expensive)? cheap How many cubic yards of concrete? 75 The cost is $7500
What grade of concrete (low/cheap, high/expensive)? high How many cubic yards of concrete? 75 The cost is $11250
What grade of concrete (low/cheap, high/expensive)? expensive How many cubic yards of concrete? 75 The cost is $11250
Code:
#include<stdio.h>
#include<string.h>
int main()
{
int yard;
char concrete[15];/*Declaring variables*/
printf("What grade of
concrete(low/cheap,high/expensive)?\n");
scanf("%s",concrete);
printf("How many cubic yards of concrete?\n");
scanf("%d",&yard);/*Reading input from the
user*/
if(strcmp("low",concrete)==0||strcmp("cheap",concrete)==0)
{ /*If low or chep*/
if(yard<200)
{/*If yard less than 200 we
multiply yard*100*/
printf("The cost
is $%d",yard*100);
}
else if(yard<=400)
{/*If yard less than or equals 400
we multiply yard*95*/
printf("The cost
is $%d",yard*95);
}
else if(yard>400)
{/*If yard greater than 400 we
multiply yard*95*/
printf("The cost
is $%d",yard*90);
}
}
else
if(strcmp("high",concrete)==0||strcmp("expensive",concrete)==0)
{/*IF high or expensive*/
if(yard<250)
{/*If yard less than 250 we
multiply yard*150*/
printf("The cost
is $%d",yard*150);
}
else
{/*If yard grater or equals to 250
we multiply yard*135*/
printf("The cost
is $%d",yard*135);
}
}
}
output:
Indentation: