trouble with a simple function

So i have some code that is coming up with an error on line 15 saying it needs a ; can some one explain what is going on here?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

double n1;
int n2;
double sum = (n1, n2);
void main()
{
	cin>>n1;
	cin>>n2;
	cout<<"the average is" <<sum<<endl;
}

double sum= (n1, n2)
{
	return ((n1+n2)/2);
}

thank you
the program should cin 2 numbers then use a function to find the average of the 2.
double sum = (n1, n2);
Function prototype does not use assignment operator =. You just need the types of the parameters it takes, not the actual names.

double sum (double, int);


cout<<"the average is" <<sum<<endl;
Function call - uses () to indicate function call and names of arguments to be sent.

cout<<"the average is " <<sum(n1,n2)<<endl;


double sum= (n1, n2)
Function definition does not use assignment operator =. Include the types of the arguments along with the names.

double sum(double n1, int n2)


Edit - I usually try to avoid using the same name of variable in multiple functions.
Last edited on
Another thing to mention is that the main function returns an int so the return type should be int and not void
thank you so much you are amazing!!
Topic archived. No new replies allowed.