### Problem with while statement

I am trying to get my program to ask for a character input, and based on that input, ask the user to put in different numerical values for certain questions. I tried to get the first portion done and when I enter "a" it terminates and says "Done". What am I doing wrong? Here's the code;

// Program to input the legs of a right triangle
// Calculate and print the hypotenuse
// a^2 + b^2 = c^2

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
double a,b, // triangle legs;input by user
c ; // triangle hypotenuse; calculated by program

// print decimals with 2 places
cout << fixed << showpoint << setprecision (2);

cout<< "==================================================\n\n";
cout<< "\tCalculations with Geometric Solids\n\n";
cout<< "==================================================\n\n";
//Prompt the user to enter a character
// to select a solid
cout<<"This program will perform some calculations for a ";
cout<<"\nsphere, a cylinder or a rectangular solid.\n";
cout<<"\nTo calculate for a cylinder, input a (or A) ";
cout<<"\nTo calculate for a sphere, input b (or B )";
cout<<"\nTo calculate for a rectangular prism, input c ( or C)";
cout<<"\n\nInput a (or A), b (or B), or c (or C) ";

{
cout << "\nInput triangle legs ";
cin >> a >> b;
cout <<"Please input the value for the legs:" << endl<<endl;
cout << "\ta = " << a <<endl;
cout << "\tb = " << b << endl<<endl;

c = sqrt (a*a + b * b ) ;
cout <<"The length of the hypotenuse is " << c << "."<< endl;

cout << "\n\nWould you like to enter the legs for more triangles? Yes or no? ";
}

cout << "\n\nDone! \n\n";

return 0;
}
What do these two statement mean?

Can you say what value answer contains?

Last edited on
You can see what minor changes I've made and the print out.
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````#include #include #include using namespace std; int main() { double a,b, // triangle legs;input by user c ; // triangle hypotenuse; calculated by program char answer; // print decimals with 2 places cout << fixed << showpoint << setprecision (2); cout<< "==================================================\n\n"; cout<< "\tCalculations with Geometric Solids\n\n"; cout<< "==================================================\n\n"; //Prompt the user to enter a character // to select a solid //cout<<"This program will perform some calculations for a "; //cout<<"\nsphere, a cylinder or a rectangular solid.\n"; //cout<<"\nTo calculate for a cylinder, input a (or A) "; //cout<<"\nTo calculate for a sphere, input b (or B )"; //cout<<"\nTo calculate for a rectangular prism, input c ( or C)"; //cout<<"\n\nInput a (or A), b (or B), or c (or C) "; //answer = 'a(orA),b(orB),c(orC)'; //cin>>answer; //while (answer == 'a(orA)') //{ cout << "\nInput triangle legs "; cin >> a >> b; //cout <<"Please input the value for the legs:" << endl<> answer; //} cout<< "\n\nDone! \n\n"; return 0; }``````
/*
==================================================

Calculations with Geometric Solids

==================================================

Input triangle legs 3 4
The length of the hypotenuse is 5.00.

Would you like to enter the legs for more triangles? Yes or no? n

Done!

Process returned 0 (0x0) execution time : 22.891 s
Press any key to continue.*/
Topic archived. No new replies allowed.