please help me fix!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2009
Posts: 38
Reputation: xfreebornx has a little shameless behaviour in the past 
Solved Threads: 0
xfreebornx xfreebornx is offline Offline
Light Poster

please help me fix!!

 
0
  #1
Aug 24th, 2009
#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;
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 132
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster

Re: please help me fix!!

 
0
  #2
Aug 24th, 2009
  1. int a,b,c;
  2. cout <<"average is:"<<average(a,b,c);
  3. 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:
  1. int a,b,c;
  2. cin >>a>>b>>c;
  3. cout <<"average is:"<<average(a,b,c);
Also, the function is not defined to take 3 arguments. This will fit your call better:
  1. double average(int x, int y, int z)
  2. {
  3. return (x+y+z)/3;
  4. }
Last edited by Tom Gunn; Aug 24th, 2009 at 4:19 pm.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,401
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: please help me fix!!

 
-7
  #3
Aug 24th, 2009
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]
Last edited by Ancient Dragon; Aug 24th, 2009 at 4:20 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 12
Reputation: dennis.wu is an unknown quantity at this point 
Solved Threads: 0
dennis.wu dennis.wu is offline Offline
Newbie Poster

Re: please help me fix!!

 
0
  #4
Aug 24th, 2009
Where you go

  1. #include <iostream>
  2. using namespace std;
  3. double average(int,int,int);
  4. int main()
  5. {
  6. int a,b,c;
  7. cin >>a>>b>>c;
  8. cout <<"average is:"<<average(a,b,c) << endl;
  9. return 0;
  10. }
  11.  
  12. double average(int x,int y, int z)
  13. {
  14. return (x+y+z)/3.0;
  15. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 9
Reputation: thug line has a little shameless behaviour in the past 
Solved Threads: 0
thug line thug line is offline Offline
Newbie Poster

Re: please help me fix!!

 
-1
  #5
Aug 24th, 2009
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™
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC