Code:
#include<stdio.h>
#include <stdlib.h>
#include<conio.h> //Not needed in Dev C++//
#define PI 3.1415
float Area_of_Rectangular(float length,float width);
float Area_of_Circle(float radius);
int main()
{
int rooms,i;
float length1,length2,width1,width2,aor,radius1,radius2,aoc;
char answer;
printf("Please enter the number of the rooms:");
scanf("%d",&rooms);
for(i=0;i<rooms;i++){
printf("Is room#%d in a rectangular shape?(y/n)\n",i+1);
scanf(" %c",&answer); //note leading space to skip any whitespace, and thus read the next non-space character.//
if (answer == 'y' || answer == 'Y'){
printf("Give length for room#%d:",i+1);
scanf("%f",&length1);
printf("Give width for room#%d:",i+1);
scanf("%f",&width1);
aor=Area_of_Rectangular(length1,width1);
printf("The area of the rectangle room#%d is :%f\n",i+1,aor);
printf("Does room#%d have a balcony?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Is the balcony of room#%d in a rectangular shape?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Give length for balcony of room#%d:",i+1);
scanf("%f",&length2);
printf("Give width for balcony of room#%d:",i+1);
scanf("%f",&width2);
aor=Area_of_Rectangular(length2,width2);
if(aor<width1){
printf("The area of the rectangular balcony of room#%d is :%f ",i+1,aor);
}
else{
printf("Sorry but the size of the balcony cannot exceed the width and/or length of the room\n");
}
}
else if (answer == 'n' || answer == 'N'){
printf("Is the balcony of room#%d in a semicircular shape?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Give radius for balcony of room#%d: ",i+1);
scanf("%f",&radius2);
aoc=Area_of_Circle(radius2)/2.0; //note:We divide the Area of Circle so we can take the Area of the Semicircle//
if(radius2*2<width1){
printf("The area of the semicircular balcony of room#%d is :%f ",i+1,aoc);
}
else{
printf("Sorry but the size of the balcony cannot exceed the width of the room\n");
}
}
else if(answer == 'n' || answer == 'N'){
printf("Sorry but we can't give any other choices for you to check the area of your balcony.Check back for more updates at www.*****.com.Thank you for using this program\n");
}
}
}
}
else if (answer == 'n' || answer == 'N'){
printf("Is room#%d in a circular shape?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Enter the radius for room#%d:",i+1);
scanf("%f",&radius1);
aoc=Area_of_Circle(radius1);
printf("The area of the circular room#%d is :%f\n",i+1,aoc);
printf("Does room#%d have a balcony?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Is the balcony of room#%d in a rectangular shape?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Give length for balcony of room#%d:",i+1);
scanf("%f",&length2);
printf("Give width for balcony of room#%d:",i+1);
scanf("%f",&width2);
aor=Area_of_Rectangular(length2,width2);
if((width2<radius1)&&(length2<2*radius1)){
printf("The area of the rectangular balcony of room#%d is :%f ",i+1,aor);
}
else{
printf("Sorry but the width of the balcony cannot exceed the radius of the room and/or the length cannot exceed it's diameter\n");
}
}
else if (answer == 'n' || answer == 'N'){
printf("Is the balcony of room#%d in a semicircular shape?(y/n)\n",i+1);
scanf(" %c",&answer);
if (answer == 'y' || answer == 'Y'){
printf("Give radius for balcony of room#%d: ",i+1);
scanf("%f",&radius2);
aoc=Area_of_Circle(radius2)/2;
if(radius2<radius1){
printf("The area of the semicircular balcony of room#%d is :%f ",i+1,aoc);
}
else{
printf("Sorry but the radius of the balcony cannot exceed the radius of the room\n");
}
}
else if (answer == 'n' || answer == 'N'){
printf("Sorry but we can't give any other choices for you to check the area of your balcony.Check back for more updates at www.*****.com.Thank you for using this program\n");
}
}
}
else if (answer == 'n' || answer == 'N'){
printf("\n");
}
}
else if(answer == 'n' || answer == 'N'){
printf("Sorry but we can't give any other choices for you to check the area of your room.Check back for more updates at www.*****.com.Thank you for using this program\n");
}
}
}
getch();
system("PAUSE");
return 0;
}
float Area_of_Rectangular(float length,float width)
{
float area_of_rect_room;
area_of_rect_room=length*width;
return(area_of_rect_room);
}
float Area_of_Circle(float radius)
{
float area_of_circ_room;
area_of_circ_room=PI*radius*radius;
return(area_of_circ_room);
}