Need help to fix the function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Demo {
     private:
          int value;
     public:
          int getValue() { return value; }
          void setValue(int value) { value = value; }
};
void display( const Demo & d )
{
     cout << d.getValue() << endl;
}
void getInput( const Demo & d )
{
     int value;
     cout << "Enter an integer";
     cin >> value;
     d.setValue(value);
}

I don't know the problem of it, since my instructor not offerd a test driver for me.
Last edited on
This should work
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
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

class Demo 
{
     private:
          int value;
     public:
          int getValue() { return value; }
          void setValue(int value) { this->value = value; }
};

void display(Demo &d)
{
     cout << d.getValue() << endl;
}

void getInput(Demo &d )
{
     int value;
     cout << "Enter an integer";
     cin >> value;
     d.setValue(value);
}

int main(void)
{
  Demo demo;
  
  getInput(demo);
  display(demo);

  system("pause");
  return EXIT_SUCCESS;
}
Thanks a lot. It works!
Topic archived. No new replies allowed.