Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1095479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:07:53+00:00 2026-05-17T00:07:53+00:00

This program is supposed to judge the height of multiple buildings by the type

  • 0

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;
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:07:54+00:00Added an answer on May 17, 2026 at 12:07 am

    A While loop is of the form:

    while(condition)
    {
        body of code
    }
    

    And a do while is of the form:

    do
    {
        body of code
    } while(condition);
    

    The difference is that the do while loop guarantees the body of the loop will execute at least once.

    The code you posted is a mix of the two. Figure out which type of while loop you need for this particular problem as this appears to be homework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a program that is supposed to prompt user for hours worked and
This is a program that is supposed to prompt the user to enter three
I have spent many hours working on this program that is supposed to play
This program is supposed to calculate the number of degrees below 60 on a
This program is supposed to run through a while loop twice. The first time
This program is supposed to take in a three digit number and change it
Update this program is supposed to keep track of the number of times each
Suppose that I have a Java program within an IDE (Eclipse in this case).
This program stores pairs in a map, counting the number of times a word
This program I'm doing is about a social network, which means there are users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.