954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

please help me fix!!

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

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

xfreebornx
Light Poster
38 posts since Jul 2009
Reputation Points: -13
Solved Threads: 0
 
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;
}
Tom Gunn
Master Poster
733 posts since Jun 2009
Reputation Points: 1,446
Solved Threads: 135
 

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]

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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;
}
dennis.wu
Newbie Poster
12 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 

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

#include
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 "<

thug line
Newbie Poster
10 posts since Jul 2009
Reputation Points: 2
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You