Hello,
main.cpp

#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>
#include "Triangle.h"

using namespace std;

int main()
{
 Triangle myTriangle;
 int side1;
 double side2;
 double side3;
 string input;
 char ch;

 do
 {
   cout << "Triangle ADT Program" << endl;
   cout << "Enter the side lengths :" << endl;
   cout << "---------------------" << endl;

   cout << "Enter length 1> ";
   getline(cin, input);
   side1 = myTriangle.setside1(side1);

   cout << "Enter length 2> ";
   getline(cin, input);
   side2 = myTriangle.setside2(side2);

   cout << "Enter length 3> ";
   getline(cin, input);
   side3 = myTriangle.setside3(side3);

   cout << "---------------------" << endl;
   cout << "This triangle is a ";  myTriangle.getTriangle(); cout << endl;
   cout << "The area of the triangle is ";  myTriangle.getArea(); cout << endl;

   cout << "Would you like to modify any of the lengths? y/n ";
   cin >> ch;

 }while(ch == 'y' || ch == 'Y');

 return 0;
}

Tringle.cpp

#include <iostream>
#include "Triangle.h"
#include 
using namespace std;

Triangle::Triangle() : side1(0),side2(0),side3(0)
{
}

Triangle::Triangle(double a, double b, double c)
{
 side1 = a;
 side2 = b;
 side3 = c;
}

void Triangle::setside1(double newside1)
{
 *side1 = newside1;
}
double Triangle::getside1() 
{
 return side1;
}

void Triangle::setside2(double newside2)
{
 side2 = newside2;
}
double Triangle::getside2() 
{
 return side2;
}

void Triangle::setside3(double newside3)
{
 side3 = newside3;
}
double Triangle::getside3() 
{
 return side3;
}

double Triangle::getArea() 
{
 double s;
 s = ( side1 + side2 + side3 ) / 2;
 return sqrt( s * ( s - side1 ) * ( s - side2 ) * ( s - side3));
}

void Triangle::getTriangle() 
{
 if( ( side1 * side1 ) + ( side3 * side3 ) == ( side2 * side2 ) )
 {
   cout << "right triangle";
 }else if( side1 == side2 && side2  == side3 )
 {
   cout << "equilateral triangle";
 }else if( side1 == side2 || side2 == side3 || side1 == side3 )
 {
   cout <<  "isosceles triangle";
 }
}

Tringle.h

#ifndef TRIANGLE_H
#define TRIANGLE_H

class Triangle
{
public:
 Triangle();
 Triangle(double a, double b, double );

 void setside1(double newLength1);
 double getside1() const;

 void setside2(double newLength2);
 double getside2() const;

 void setside3(double newLength3);
 double getside3() const;

 double getArea() const;

 void getTriangle() const;

private:
 double side1;
 double side2;
 double side3;
};
#endif

-------------------------
Error

main.cpp:26:10: error: assigning to 'int' from incompatible type 'void'
   side1 = myTriangle.setside1(side1);
         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:30:10: error: assigning to 'double' from incompatible type 'void'
   side2 = myTriangle.setside2(side2);
         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:34:10: error: assigning to 'double' from incompatible type 'void'
   side3 = myTriangle.setside3(side3);
         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.

--------------------
Do you know what's wrong with this code and how to fix it ?

1) side1 has no value so you are passing junk onto myTriangle.setside1()
2) myTriangle.setside1() is a void function and returns nothing, therefore you can't load that nothing into side1

in line 26 in main the value of side 1
2 i know that but what shold i do ? what changes should i able
and thank u

You have void Triangle::setside1(double newside1) and you called this method by this side1 = myTriangle.setside1(side1); and you have set side1 as int.

First of all, as WaltP said, you are passing junk, as side1 has garbage value ( basically no usefull value ), secondly you need to pass a double variable, not an int. Another error is that you are returning nothing ( void ) from the function, but in main you have a line of which says that the function returns double.

Function return type mis-match is the error that has occured 3 times, for these 3 functions void Triangle::setside1(double newside3), void Triangle::setside2(double newside2), void Triangle::setside3(double newside3). You need to change void to double and in the functions you need a return statement. Also, you need initialize the variables side1, side2 etc before you pass them to a function.

Thanks all i fixed it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.