This is my first time creating a function and I am not sure I understand it all and the return isnt working. If anyone could give me some pointers that would be great.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
// this is my first created function
double doPythag(double c, double a, double b)
{
c = (sqrt(pow(a, 2.0) + (pow(b, 2.0))));
return c;
}
int main()
{
string answer = "Yes";
double biggest = -1, a, b, c;
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 ";
cout << c << endl; // keeps saying c is undefined
cout << "Do you want to continue (\"Yes\" or \"No\")?";
cin.ignore();
getline(cin, answer);
}
if (biggest > -1)
{
cout << "The largest answer for side c was " << biggest << endl;
}
}
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
// this is my first created function
//double doPythag(double c, double a, double b)double doPythag(double a, double b)
{
double c = (sqrt(pow(a, 2.0) + (pow(b, 2.0))));
return c;
// Or
// return (sqrt(pow(a, 2.0) + (pow(b, 2.0))));
}
int main()
{
string answer = "Yes";
double biggest = -1, a, b, c;
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 ";
c = doPythag(a,b);
cout << c << endl; // keeps saying c is undefined
cout << "Do you want to continue (\"Yes\" or \"No\")?";
cin.ignore();
getline(cin, answer);
}
if (biggest > -1)
{
cout << "The largest answer for side c was " << biggest << endl;
}
}
You never do anything with biggest, but I suppose one day you shall :)