getting error..

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
#include<iostream>
#include<conio.h>
using namespace std;
class evs
{
      private:
              int k;
              int b;
              int result;
              public:
                     int value ()
                     {
                         cout<<"enter value 1:";
                         cin>>k;
                         cout<<"enter value 2:";
                         cin>>b;
                         }
                         int sum ()
                         {
                          result=k+b;
                          cout<<"The sum of both numbers you entered is:"<<result<<endl;
                          }
                          int main()
                          {
                              evs aaa;
                              aaa.value();
                              aaa.sum();
                              getch();
                              }
                              }
                            
i want to make a code that is based on class and object and is capable of getting input in first member function and sum up and give result in second member function.. i made this code but am getting some error with braces.. dont know weather its right or wrong.. any help in this regard will make you and me happy :)
The semicolon after the closing brace of evs is missing. I strongly suggest that you put the opening and closing brace on the same level.
buddy am confused in that some one told me that my whole code is wrong can you kindly chek that again.. and do me a favor copy that part of code and paste it here with correction..
hay bro its done.. :) now its working..
Ok:

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
#include<iostream>
#include<conio.h>
using namespace std;
class evs
{
      private:
              int k;
              int b;
              int result;
              public:
                     void value () // Note: You don't want to return anything so void instead of int
                     {
                         cout<<"enter value 1:";
                         cin>>k;
                         cout<<"enter value 2:";
                         cin>>b;
                     }
                     void sum () // Note: void instead of int
                     {
                          result=k+b;
                          cout<<"The sum of both numbers you entered is: "<<result<<endl;
                     }
};

int main() // Note: main ouside the class
{
  evs aaa;
  aaa.value();
  aaa.sum();
  getch();

  return 0; // Note: If you write 'int function()' you need to return a value
}
that is really cool and very help full...:) :) ... can you tell me what is meant by return a value??
If you have this

1
2
3
4
5
6
7
8
9
10
11
int Foo()
{
  return 100; // This returns the value 100
}

...

{
  int x = 0; // x is 0
  x = Foo(); // Now x is 100
}
thats good :)..
Topic archived. No new replies allowed.