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 6608505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:37:01+00:00 2026-05-25T19:37:01+00:00

#include <iostream> #include <math.h> using namespace std; int main() { double radius = 0.00;

  • 0
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    double radius = 0.00;
    double height = 0.00;
    double width = 0.00;
    double side = 0.00;
    double Area = 0.00;
    const double PI = atan(1.0)*4;
    string input = "none";

    while (input != "0") {
        cout << "Shape Menu: \n (r) rectangle \n (s) square \n (c) circle \n (0) exit" << endl;
        cin >> input;
        if (input == "r"){
            cout << "Please enter a floating point value for the height of the rectangle." << endl;
            cin >> height;
            cout << height;
            while (height <= 0)
            {
                cin.clear();
                cin.ignore(1000, '\n');
                cout << "Your input was invalid.  Please input a floating point value greater than 0.";
                cin >> height;
            }
            cout << "Please enter a floating point value greater than 0 for the width of the rectangle." << endl;
            cin >> width;
            while (width <= 0)
            {
                cin.clear();
                cin.ignore(1000, '\n');
                cout << "Your input was invalid";
                cin >> width;
            }
            Area = height*width;
            cout << "The area of a rectangle with those dimensions is " << Area << "units squared." << endl;
        }

        else if(input == "s"){
            cout << "Please enter a floating point value for the length of the side." << endl;
            cin >> side;
            if (cin.fail())
                cout << "Please enter a floating point value.";
            Area = side*side;
            cout << "The area of a square with those dimensions is " << Area << "units squared" << endl;
        }

        else if(input == "c"){
            cout << "Please enter a floating point value for the length of the radius." << endl;
            cin >> radius;
            if (cin.fail())
                cout << "Please enter a floating point value.";
            Area = radius*radius*PI;
            cout << "The area of a circle with those dimensions is " << Area << "units squared." << endl;
        }

        else if(input == "0"){
            break;
        }

        else{
            cout << "Your input does not match one of the options suggested. Please type r, s, c to get the area of a shape, or type 0 to exit." << endl;

        }
        }

    return 0;
}

I am trying to write a program that asks the user to pick from a menu of shapes, then ask for certain inputs for each type to determine the area. The problem I am having now, is trying to figure out how to raise errors when people input answers for the radius or height and width that are not numeric. The error I was trying to write for the rectangle worked for the initial incorrect input, however once the user is prompted pick another shape, if an input error occurs again, then it begins an infinite loop.

  • 1 1 Answer
  • 0 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-25T19:37:02+00:00Added an answer on May 25, 2026 at 7:37 pm

    You are using cin.clear() and cin.ignore(1000,’\n’) to skip over the invalid input in the rectangle case, which is good, but you aren’t doing that in the other cases.

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

Sidebar

Related Questions

#include <iostream> #include <math.h> using namespace std; int main() { int arraylength; int lastbig
edit: I am implementing an algorithm in c++. #include<iostream> #include<math.h> #include<string> using namespace std;
I have following code to accomplish prefix sum task: #include <iostream> #include<math.h> using namespace
My header file is as follows: #include <iostream> #include <string> #include <windows.h> #include <math.h>
I want to consider to code. First it is: #include <iostream> #include <cmath> #include
i have following simpled algorithm for calculation roots of quadratic equation #include <iostream> #include
We know that sin(x)=x-x^3/3!+x^5/5!-x^7/7!+x^9/9! and so on. I have written this code: #include <iostream>
I got surprised when I debugged my code. Here I provide example code #include<QMessageBox>
I have created an open plane area with thin cylinders on it like pucks,
I wrote a c++ program using boost library in Xcode. Here is my code.

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.