#include <iostream>
using namespace std;
double average(int x);
int main()
{
    int a,b,c;
    cout <<"average is:"<<average(a,b,c);
    cin >>a>>b>>c;
    return 0;
}

double average(int x)
{
  return (x+x+x)/3;
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

int a,b,c;
cout <<"average is:"<<average(a,b,c);
cin >>a>>b>>c;

I always wonder how it makes sense to do the work before getting the values when the work depends on the values. Try this:

int a,b,c;
cin >>a>>b>>c;
cout <<"average is:"<<average(a,b,c);

Also, the function is not defined to take 3 arguments. This will fit your call better:

double average(int x, int y, int z)
{
    return (x+y+z)/3;
}

help you fix what??? The most obvious problem is that it is using uninitialized variables a, b and c. Next, function average only takes one argument, not 3. Either change that function to accept three arguments or only pass one.

[edit]^^^ what Tom said. [/edit]

Where you go

#include <iostream>
using namespace std;
double average(int,int,int);
int main()
{
	int a,b,c;	
	cin >>a>>b>>c;
	cout <<"average is:"<<average(a,b,c) << endl;
	return 0;
}

double average(int x,int y, int z)
{
	return (x+y+z)/3.0;
}

hi.. please try this one.. im not sure if this is what you wanted but i hope this code can help you..

#include<iostream>
using namespace std;

int main()
{
float a,b,c;
double x;
// x = average of a,b,c

cout<<"Insert 3 Average: "
cin>>a;
cin>>b;
cin>>c;

x = (a+b+c)/3;

cout<<"The average is "<<x;

return 0;
}

™Thug Line™

Comments
Learn to use code tags.
This article has been dead for over six months. Start a new discussion instead.