|
| quote: | Originally posted by trancaholic
Please don't take this the wrong way, but...
The problem seem rather trivial. If you have a working compiler environment I can't see how you can fail at this. If, however, you have no knowledge of how to do simple arithmetics such as sqrt(int), and you're already giving up at this challenge, then you're probably in the wrong class, and further pursuit of this career will result in frustration and inferiority-problems.
You're entitled to deem me a stupid prejudist, but judging from the difficulty level of this problem, I guess you're at your first year of programming experience and if you think this is an overwhelming problem there's other aspects of computer science that might appeal more to you.
Though, if you have other reasons for solving this problem, than passing some programming-course, I'll be more than happy to help you out, but if this is your motive, you really ought to solve it yourself. |
dont listen to this guy, djpsi. i bombed c++ the first time i took it with a D. then i took it at a community college and got an A+. the moral of the story: It's all about how good the teacher is.
anyway, here you go. learn from it, godammit.
#include
#include
#include
int main()
{
int n = 0;
double x;
double h = 0;
double hsum = 0;
double gmean;
double hmean;
double sum = 0;
while(x!=999){
// if ( x==999)
// break;
cout << "Enter a number ( 999 to end )\n";
cin >> x;
sum+= x;
h = 1.0 / x;
hsum+= h;
if( x != 999)
n++;
}
gmean = pow( sum - 999, 1.0/n );
hmean = n / hsum;
cout << "The geometric mean is " << setprecision(2)
<< setiosflags( ios::fixed | ios::showpoint ) << gmean << endl;
cout << "The harmonic mean is " << setprecision(2)
<< setiosflags( ios::fixed | ios::showpoint ) << hmean << endl;
|