Try Run C Program Stop Enter Value Dimension Radius Width Problem Include Using Namespace Q24299282

I try to run this c++ program but it stop after I enter thevalue for the dimension(radius, width…) Where is the problem?

# include <iostream>

using namespace std;

// Function prototypes

void check(double, string);

int main()

{

const double PI = 3.14159;

char shape;

double radius, height, length, width, volume;

cout << “Enter the shape for which you want to calculatethe volume.n”

<< “use s for sphere, c for cylinder, or b for boxn.”<< endl;

cin >> shape;

//check of input

while (shape != ‘s’ && shape != ‘S’ && shape !=’c’ && shape != ‘C’

&& shape != ‘b’ && shape != ‘B’)

{

cout << “Your entry was invalid!” << endl;

cout << “Enter the shape for which you want to calculatethe volume.n”

<< “use s for sphere, c for cylinder, or b for boxn.”<< endl;

cin >> shape;

}

//switch to calculate volume

switch (shape)

{

case ‘s’:

case ‘S’:

cout << “Enter the radius of the sphere. “;

cin >> radius;

//check input

check(radius, “radius of the sphere”);

volume = 4.0 / 3 * PI * radius * radius * radius;

cout << “The volume of a sphere with radius of ” <<radius

<< ” has a volume of ” << volume << “.n”;

break;

case ‘c’:

case ‘C’:

cout << “Enter the radius of the cylinder. “;

cin >> radius;

//check input

check(radius, “radius of the cylinder”);

cout << “Enter the height of the cylinder. “;

cin >> height;

//check input

check(height, “height of the cylinder”);

volume = PI * radius * radius * height;

cout << “The volume of a cylinder with radius of “<< radius

<< ” and height of ” << height << ” has avolume of ” << volume << “.n”;

break;

default:

cout << “Enter the height of the box. “;

cin >> height;

//check input

check(height, “height of the box”);

cout << “Enter the length of the box. “;

cin >> length;

//check input

check(length, “length of the box”);

cout << “Enter the width of the box. “;

cin >> width;

//check input

check(width, “width of the box”);

volume = height * length * width;

cout << “The volume of a box with a height of ” <<height << “, a lengthe of “

<< length << ” and width of ” << width<< ” has a volume of ” << volume

<< “.n”;

}

return 0;

}

/*

function to check the validity

*/

void check(double dimension, string standsFor)

{

while (dimension < 0)

{

cout << “The ” << standsFor << ” cannot beless than zero. Please enter ” << standsFor << “again.” << endl;

cin >> dimension;

}

}

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *