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

  • SEARCH
  • Home
  • 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 1074191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:05:22+00:00 2026-05-16T21:05:22+00:00

I am putting together a program that will calculate the area of either a

  • 0

I am putting together a program that will calculate the area of either a triangle or a square and then prompt the user whether they wish to calculate another. I’ve got the code working to the point that it will calculate the area of either shape, but then doesn’t continue with the rest of the code. For example is square is selected, the area is calculated and then goes back to the prompt for the square’s side. I am assuming that it is again the while looping forever, but don’t know how to stop the loop from going on endlessly.

Here is my code:

 #include<stdio.h>
 #include<math.h>
 
 int main(void)
 
 {
     float sq_side, tri_base, tri_height, Area;
     char shape, cont = 'Y';
     
     printf("Please select the type of shape you desire to calculate the area for:\n");
     printf("                                                                     \n");
     printf("   Square = S                             Triangle = T               \n");
     printf("   -------                                    x                      \n");
     printf("   :     :                                   x x                     \n");
     printf("   :     :                                  x   x                    \n");
     printf("   -------                                 xxxxxxx                   \n");
     printf("                                                                     \n");
     printf("Please select either S or T:");
     scanf("%c", &shape);
     while (cont != 'n' && cont != 'N')
     
        if (shape == 'S' || shape == 's')
        {
            printf("What is the length of the sides of the square?:\n");
            scanf("%f", &sq_side);
         
            Area = pow(sq_side,2);
         
            printf("The area of the square is %.2f.\n", Area);
        }   
         
        else if (shape == 'T' || shape == 't')
        {
            printf("What is the length of the base of the triangle?:\n");
            scanf("%f", &tri_base);
            printf("What is the height of the triangle?:\n");
            scanf("%f", &tri_height);
            
            Area = 0.5 * tri_base * tri_height;
            
            printf("The area of the triangle is %.2f.\n", Area);
        }   
        
        else 
        {
        printf("Error:  You have select an incorrect option.");
        }
        
        printf("Do you wish to calculate a new shape?");
        fflush(stdin);
        scanf("%c", &cont);
        
     return(0);
     
 }
 
  • 1 1 Answer
  • 3 Views
  • 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-16T21:05:22+00:00Added an answer on May 16, 2026 at 9:05 pm

    You’re missing curly braces. The result was that only the if statement (which includes the chain of else ifs) was actually in the loop body. The printf (and later) is not part of this compound statement.

     while (cont != 'n' && cont != 'N')
     {
        if (shape == 'S' || shape == 's')
        {
            printf("What is the length of the sides of the square?:\n");
            scanf("%f", &sq_side);
    
            Area = pow(sq_side,2);
    
            printf("The area of the square is %.2f.\n", Area);
        }   
    
        else if (shape == 'T' || shape == 't')
        {
            printf("What is the length of the base of the triangle?:\n");
            scanf("%f", &tri_base);
            printf("What is the height of the triangle?:\n");
            scanf("%f", &tri_height);
    
            Area = 0.5 * tri_base * tri_height;
    
            printf("The area of the triangle is %.2f.\n", Area);
        }   
    
        else 
        {
        printf("Error:  You have select an incorrect option.");
        }
    
        printf("Do you wish to calculate a new shape?");
        fflush(stdin);
        scanf("%c", &cont);
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I putting together a page that will display a set of stored values. I
I'm putting together a simple web page that presents the user with a jQuery
I am currently putting together some jQuery that will activate slideDown() when an element
I'm putting together an app that will show a news item's location in Google
Putting together a collection of Bash scripts that will be released to a wider
I am putting together a program that takes 20 random numbers, sorts them into
So I've been putting this graphics transformation program together and suddenly some change I
I'm putting together a simple drop down that contains nested ul's. I want it
I am putting together an Java application that needs to display some basic lab
I am currently putting together a rails-based web application which will only serve and

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.