Whats's wrong?!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <conio.h>
#include <math.h>

using namespace std;

class SegReta {
      int x1, y1, x2, y2;
      public:
             SegReta () {}
             void Datain();
             float Distance();
}

void SegReta::Datain()
{
      cout << "First point(x1, y1)\n\nx1: ";
      cin >> x1;
      cout << "y1: ";
      cin >> y1;
      cout << "Second point(x2, y2)\n\nx2: ";
      cin >> x2;
      cout << "y2: ";
      cin >> y2;
      cout << "The distance between the points is ";
}

float SegReta::Distance()
{
      return (float)sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main() {
    
    SegReta properties;
    
    properties.Datain();
    properties.Distance();
    
    getch();
    return 0;
}


16 new types may not be defined in a return type
16 two or more types in declaration of 'Datain'
16 prototype for 'SegReta SegReta Datain()' does not much any in class 'SegReta'
16 'SegReta SegReta Datain()' and 'void SegReta Datain()' cannot be overloaded
Last edited on
Please post the compile error. And as a general rule, try to make your code in english, o that all of us understand it easier.
And as a general rule, try to make your code in english


Umm, code is code, not English. But forgiving laziness in the complaint, there is no need for people to write 'their code in English'. You should be able to understand. After all the programming language remains the same.



Last edited on
Sounds like your code is not as posted (already noted you change your code to 'properties.Distance();')

I think, from your edits, that the compiler is saying you function returns a type SegReta from the Datain function, rather than a void.
Last edited on
You need a semicolon behind a class definition:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
using namespace std;

class SegReta {
      int x1, y1, x2, y2;
      public:
             SegReta () {}
             void Datain();
             float Distance();
};

void SegReta::Datain()
{

...


Edit: Please also try to avoid conio.h, it's non-standard c++ and you really don't need it here.
Last edited on
Thank you.
------------
But I'm still having a problem in the program.
The function properties.Distance(); isn't calculating the distance...
What's the problem there?
------------
I like to use the getch(); like the system("pause");.
Is it better use the last?
Last edited on
up.
exiledAussie wrote:
Umm, code is code, not English. But forgiving laziness in the complaint, there is no need for people to write 'their code in English'. You should be able to understand. After all the programming language remains the same.


I would have to disagree with this. The naming of variables and functions is very important so that we do not have to waste our time looking through the code to figure out what it's purpose is.

@Maerle:
1) It looks fine to me...maybe you just aren't printing it out?
2) Use std::cin.get(); instead of [/code]getch();[/code]. The former works on all systems.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <math.h>

using namespace std;

class SegReta {
      int x1, y1, x2, y2;
      public:
             SegReta () {}
             void Datain();
             float Distance();
};

void SegReta::Datain()
{
      cout << "First point(x1, y1)\n\nx1: ";
      cin >> x1;
      cout << "y1: ";
      cin >> y1;
      cout << "Second point(x2, y2)\n\nx2: ";
      cin >> x2;
      cout << "y2: ";
      cin >> y2;
      cout << "The distance between the points is "<<Distance()<<endl;
}

float SegReta::Distance()
{
      return (float)sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main() {
    
    SegReta properties;
    
    properties.Datain();
    properties.Distance();
    
    return 0;
}
Yes. It was just the print.

@Fideraco:
the std::cin.get(); didn't work.
I had a problem with all of those also.
I now use cin.ignore().get();
without any problems.
Topic archived. No new replies allowed.