Ok I thank whomever it was that helped me out yesterday but I have one more question. I want all of the Pythagorean calculation to occur in the function. Why isnt it calculating the biggest. Is there a way to modify biggest inside the doPythag function without modifying main anymore. Comments are provided in code.
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
void doPythag()
{
double a, b, c;
cout << "Please enter the length of side a: ";
cin >> a;
cout << "Please enter the length of side b: ";
cin >> b;
c = (sqrt(pow(a, 2.0) + (pow(b, 2.0))));
cout << "Side c is ";
cout << c << endl;
}
int main()
{
string answer = "Yes";
double biggest = -1;
while (answer == "Yes")
{
doPythag();
cout << "Do you want to continue (\"Yes\" or \"No\")?";
cin.ignore();
getline(cin, answer); //Program works up until this point
}
if (biggest > -1) // this part does not calculate
{
cout << "The largest answer for side c was " << biggest << endl;
}
}
I would recommend taking the cout and cin out of your doPythag function (the way you have it before). You've made your function a lot less flexible, what if your reading points from a file and need to know their distance to the origin?
You've also made it so you have no idea what c is, so you can't update biggest.
You basically need double doPythag(double a, double b) to return c. Once it does, check if c is greater than biggest, and if it is, make biggest equal c. This comparison is all done within the while loop.