Function call problem

Hi, I'm new to programming and I need help with this problem. I have this piece of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstdlib>
#include <iostream>

using namespace std;

void add1(void) 
{
  double a[2]={3.1, 1.4};
  double b[2]={3.5, 1.5};
  double c[2];
  c[0]=a[0]+b[0];
  c[1]=a[1]+b[1];
  printf("%1.1f %1.1f", c[0], c[1]);
}

int main(int argc, char *argv[])
{
    add1();
    getchar();
    return 0;
}


I need to rewrite it this way, but it doesn't work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <cstdlib>
#include <iostream>

using namespace std;

void add1(double a[2], double b[2], double c[2])
{
  c[0]=a[0]+b[0];
  c[1]=a[1]+b[1];
  printf("%1.1f %1.1f", c[0], c[1]);
}

int main(int argc, char *argv[])
{
    add1({3.1, 1.4}, {3.5, 1.5}, {0.0,0.0});
    getchar();
    return 0;
}


What am I doing wrong? Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstdlib>
#include <iostream>

using namespace std;

void add1(double a[2], double b[2], double c[2])
{
	c[0] = a[0] + b[0];
	c[1] = a[1] + b[1];
	printf("%1.1f %1.1f", c[0], c[1]);
}

int main(int argc, char *argv[])
{
	double a[2] = { 3.1, 1.4 };
	double b[2] = { 3.5, 1.5 };
	double c[2]; // May want to initialize these to 0 or you'll get garbage.
	add1(a, b, c);
	getchar();
	return 0;
}
Thank you very much!
Topic archived. No new replies allowed.