This program is supposed to judge the height of multiple buildings by the type of building and number of stories. There is a loop that continues to ask the questions until the user enters "0" for type of building. At the end, it prints a report showing the types of buildings and how many of each conform to building codes. I am having problems compiling the program, but I'm not sure if the loop is right either.
#include <stdio.h>
#include <math.h>
//constants
#define MIN_HEIGHT 180
#define MAX_HEIGHT 220
#define ROOF_MULT 2.0
int main()
{
//variables
int type, stories, F_TO_MECH, osum, rhsum, msum;
double height, ADD_MECH_HEIGHT, code, F_HEIGHT;
osum=0, rhsum=0, msum=0;
//Find type of building and number of stories.
printf("Enter a building type (1=Office, 2=Residential/Hotel, 3=Mixed-Use, 0=Stop): ");
scanf("%d", &type);
printf("Enter the number of stories in the building: ");
scanf("%d", &stories);
//Switch to differentiate constants of building types.
while (type != 0)
{
do
{
switch (type) //Switch for building constants.
{
case 1: F_HEIGHT=3.9;
ADD_MECH_HEIGHT=2.0;
F_TO_MECH=20;
break;
case 2: F_HEIGHT=3.1;
ADD_MECH_HEIGHT=1.55;
F_TO_MECH=30;
break;
case 3: F_HEIGHT=3.5;
ADD_MECH_HEIGHT=1.75;
F_TO_MECH=25;
break;
}
//Formula to find height.
height = (stories * F_HEIGHT) + ((F_HEIGHT * ROOF_MULT) + ADD_MECH_HEIGHT) + (ADD_MECH_HEIGHT * (stories / F_TO_MECH));
if( height <= MAX_HEIGHT )
{
if( height >= MIN_HEIGHT )
{
switch (type)
{
case 1: osum = osum++;
case 2: rhsum = rhsum++;
case 3: msum = msum++;
}
}
}
printf("Enter a building type (1=Office, 2=Residential/Hotel, 3=Mixed-Use, 0=Stop): ");
scanf("%d", &type);
printf("Enter the number of stories in the building: ");
scanf("%d", &stories);
} //End While statment.
//print results.
printf("Building Type Count \n-------------------\nOffice %3.0f\nRes/Hotel %3.0f\nMix-Use %3.0f\n", osum, rhsum, msum;
return 0;
}
Here's the error I get when I try to compile: assign04.c:79: error: expected ‘while’ before ‘printf’ assign04.c:82: error: expected declaration or statement at end of input
Any help would be appreciated.
Updated:
int main()
{
//variables
int type, stories, F_TO_MECH, osum, rhsum, msum;
double height, ADD_MECH_HEIGHT, F_HEIGHT;
osum=0, rhsum=0, msum=0;
//Find type of building
printf("Enter a building type (1=Office, 2=Residential/Hotel, 3=Mixed-Use, 0=Stop): ");
scanf("%d", &type);
//Switch to differentiate constants of building types.
do
{
//find the number of stories.
printf("Enter the number of stories in the building: ");
scanf("%d", &stories);
switch (type) //Switch for building constants.
{
case 1: F_HEIGHT=3.9;
ADD_MECH_HEIGHT=2.0;
F_TO_MECH=20;
break;
case 2: F_HEIGHT=3.1;
ADD_MECH_HEIGHT=1.55;
F_TO_MECH=30;
break;
case 3: F_HEIGHT=3.5;
ADD_MECH_HEIGHT=1.75;
F_TO_MECH=25;
break;
}
//Formula to find height.
height = (stories * F_HEIGHT) + ((F_HEIGHT * ROOF_MULT) + ADD_MECH_HEIGHT) + (ADD_MECH_HEIGHT * (stories / F_TO_MECH));
if( height <= MAX_HEIGHT )
{
if( height >= MIN_HEIGHT )
{
switch (type)
{
case 1: osum = osum++;
case 2: rhsum = rhsum++;
case 3: msum = msum++;
}
}
}
} while (type != 0); //End While statment.
//print results.
printf("Building Type Count \n-------------------\nOffice %3.0f\nRes/Hotel %3.0f\nMix-Use %3.0f\n", osum, rhsum, msum;
return 0;
}