i can't find the differance

i can't see the differance between my code and the example one in the tutorial under clases 1. i copyed the one in he tutorial by typing it instead of copying and pasting to help me remember howerver i can't see the differance brween mine and the example exept mine won't run and the exanple will the first ones mine(it won't run) and the second one is the example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

class recg {
      int x,y;
      public:
             void go (int,int);
             int area () {return (x*y);}
      };
      
      void recg::go (int a,int b){
           x = a;
           y = b;
           }
           
           int main () {
               recg rec,reca;
               rec.go (4,3);
               reca.go (20,5);
               cout<<"4 by 3="<<rec.go()<<endl;
			   cout<<"\n20 by 5="<<reca.go()<<endl;
               cout<<"\n\n\n";
              return (0);
               }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

class CRectangle {
    int x, y;
  public:
    void set_values (int,int);
    int area () {return (x*y);}
};

void CRectangle::set_values (int a, int b) {
  x = a;
  y = b;
}

int main () {
  CRectangle rect, rectb;
  rect.set_values (3,4);
  rectb.set_values (5,6);
  cout << "rect area: " << rect.area() << endl;
  cout << "rectb area: " << rectb.area() << endl;
  return 0;
}

can anyone please find the problem(s) or a differance (if any)
closed account (z05DSL3A)
your code calls cout<<"4 by 3="<<rec.go()<<endl; instead of
cout<<"4 by 3="<<rec.area()<<endl;
When you call rec.go() at line 20 you forgot to pass the two integers that the function takes as arguments...
[EDIT] Or if you need to call area, you used the wrong function name, as Grey Wolf said
Last edited on
sorry for that simple mistake on lne 20,21
but even after correcting this it still won't run why???
closed account (z05DSL3A)
...wrong function name, as Zaita said

Hmmm...this is the second time the wrong name has been attributed to my posts. Is there a problem?

Grey Wolf.
@Grey Wolf
Sorry about that, I was reading something else from Zaita that's why the wrong name. I didn't want to offend you. It was just a type mistake, I corrected it.
Sorry again.

@hamo94
It works fine for me if you change the ".go()" with ".area();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

class recg {
   int x,y;
public:
   void go (int,int);
   int area () {return (x*y);}
};

void recg::go (int a,int b){
   x = a;
   y = b;
}

int main () {
   recg rec,reca;
   rec.go (4,3);
   reca.go (20,5);
   cout<<"4 by 3="<<rec.area()<<endl;
   cout<<"\n20 by 5="<<reca.area()<<endl;
   cout<<"\n\n\n";
   return (0);
}
Last edited on
@Grey Wolf: It's the Zen of question answering. I have become so elite, now I don't even have to answer the questions. I get credit for other ppl's answers :P
closed account (z05DSL3A)
@Grey Wolf
Sorry about that, I was reading something else from Zaita that's why the wrong name. I didn't want to offend you. It was just a type mistake, I corrected it.
Sorry again.

You didn't offend me, I was just concerned that there may have been a problem with the forum. As I said there was a least one other occasion of a miss quote, I have also seen posts from other that seemed to be "out side of there normal posting times".
Topic archived. No new replies allowed.