Can anyone help with pythagorean problem?

Ok I am trying to right this program that calculates the largest side of a triangle, I got that part. The problem comes from the fact that when you continue to enter "yes" in the program you are still asked the sides for a, c. Well when you type in "no" I would like the program to show you

cout << "The largest answer for side c is " << //then show the answer of the largest of the answers given while user has been using the program. Here is a sample of my code.

#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
double a, b, c;
string answer="Yes";

while (answer == "Yes")
{
cout << "Please enter the length of side a: ";
cin >> a;
cout << "Please enter the length of side b: ";
cin >> b;

cout << "Side c is " << (sqrt(pow(a, 2.0) + (pow(b, 2.0)))) << endl;


cout << "Do you want to continue (\"Yes\") or (\"No\")";
cin >> answer;

}
}
Hi,

Did you type in "yes" or "Yes", your program is expecting "Yes".

Could you use code tags? The <> button on the right under format.
Something like:
1
2
3
4
5
6
7
8
9
10
double largest = 0;
//...
c = sqrt(pow(a, 2.0) + (pow(b, 2.0)));
cout << "Side c is " << c << endl;

if( c > largest ) {
    largest = c;
}
//...
cout << The largest answer for side c is " << largest << endl; 

Topic archived. No new replies allowed.