1

I am trying to use class to create a program, that with user input, can perform the operations of the Pythagorean theorum, but i get this error:

Error (active) E0304 no instance of overloaded function "getline" matches the argument list

This is my code:

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

class PythagoreanTheorum
{

public:

    double a;
    double b;
    double c;

    void seta(double A)
    {
        a = A;
    }
    void setb(double B)
    {
        b = B;
    }

    void setc(double C)
    {
        c = C;
    }

    double calcAreea()
    {
        return a * pow(a, 2) + b * pow(b, 2) == c * pow(c, 2);
    }    

};


int main()
{
   //Define one right triangles

        PythagoreanTheorum righttriangle1;

    double a;
    double b;
    double c;
    cout << "Enter the value for a: " << endl;
    righttriangle1.a = getline(cin, a);

    cout << "Enter the value for b: " << endl;
    righttriangle1.b = getline(cin, b);


    cout << "Enter the value for c: " << endl;
    righttriangle1.c = getline(cin, c);





}
N Sandhar
  • 25
  • 4
  • Does this answer your question (out of flags today): https://stackoverflow.com/q/5844309/12448530 – Firefly Mar 29 '20 at 16:54
  • 1
    Why not use cin for entering values of a,b and c –  Mar 29 '20 at 17:06
  • Does this answer your question? [Trying to use int in getline](https://stackoverflow.com/questions/5844309/trying-to-use-int-in-getline) – S.M. Mar 29 '20 at 17:11
  • Also, calcAreea() is not proper, this is for pythagoreas theorem right? a^2 + b^2 = c^2? –  Mar 29 '20 at 17:17

2 Answers2

0

std::getline reads strings, not doubles. So you'd have to read with std::string and then convert it to double (with stod).

You can instead use >> operator for inputs, too:

cout << "Enter the value for a: " << endl;
std::cin >> righttriangle1.a;

cout << "Enter the value for b: " << endl;
std::cin >> righttriangle1.b;

cout << "Enter the value for c: " << endl;
std::cin >> righttriangle1.c;
P.P
  • 106,931
  • 18
  • 154
  • 210
0

This is how I would write the code, assuming that calcAreea() in your code is meant to show Pythagoreas Theorem being applied.

My code:

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

class PythagoreanTheorum
{
    public:
        void seta(double A)
        {
            a = A;
        }
        void setb(double B)
        {
            b = B;
        }
       void setc(double C)
        {
            c = C;
        }
        double calcTheorem()
        {
            cout<<"Applying Pythagoreas Theorem:"<<pow(a,2)<<"+"<<pow(b,2)<<"="<<pow(c,2);
        }    
    private:
        double a;
        double b;
        double c;

};


int main()
{
    //Define one right triangles
    //Test -> a = 3, b = 4, c = 5

    PythagoreanTheorum righttriangle1;

    double a;
    double b;
    double c;
    cout << "Enter the value for a: " << endl;
    cin>>a;
    righttriangle1.seta(a);

    cout << "Enter the value for b: " << endl;
    cin>>b;
    righttriangle1.setb(b);

    cout << "Enter the value for c: " << endl;
    cin>>c;
    righttriangle1.setc(c);

    righttriangle1.calcTheorem();
}

I removed string header file since it wasn't being used, I also used cin instead of getline since that's way better in this case, also I wanted to not use using namespace std; but since it was in your code I retained it & also renamed calcAreea as calcTheorem since it wasn't calculating area

EDIT: I forgot to mention I declared variables in class in private instead of public