cannot convert double

Beginner here, how do i get this double to work?

error:cpp:12: error: cannot convert ‘double’ to ‘double*’ for argument ‘1’ to ‘void thai(double*)

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
  #include <iostream>
  
  using namespace std;
  
  void thai(double *t);
  void dub(int *n);
  
  int main()
  {
     double input = 7.8;
  
     thai(input);
  
     return 0;
  }
  
  void thai(double *t)
  {
     *t *= 2;
  
  }
  void dub(int *n)
  {
     *n *= 2;
  }
'input' is a double

thai takes a double* as a parameter. Note the * there... that indicates the type is not a double... but rather is a pointer to a double.

So you need to give thai the address of a double. You can do this with the address-of operator:

 
thai( &input ); // <- note:  '&input' instead of just 'input' 
Topic archived. No new replies allowed.