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
char answer;
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<<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? ";
cin >> answer;
}
#include <iostream>
#include <cmath>
#include <iomanip>
usingnamespace 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<<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? ";
cin >> answer;
//}
cout<< "\n\nDone! \n\n";
return 0;
}