1. ## Arithmetic/Geometric/Harmonic

Hey

I'm currently stuck on a problem. I have to create a program that reads the input of two numbers and works out their Arithmetic/Geometric/Harmonic mean. It then calculates which mean is the highest and displays it on the screen.

This is what I have so far...

Code:
#include <math.h>

int main()
{
Double num1
Double num2
Double ari
Double geo
Double har

printf("enter num1");
scanf ("%d%*C" , &num1),

printf("enter num2");
scanf ("%d%*C" , &num2);

ari = ((num1+num2)/2);
printf("Arithmetic Mean =",ari);

printf("enter num1");
scanf ("%d%*C" , &num1),

printf("enter num2");
scanf ("%d%*C" , &num2);

geo = ((num1*num2)

printf("enter num1");
scanf ("%d%*C" , &num1),

printf("enter num2");
scanf ("%d%*C" , &num2);

har =

Is this correct so far? Is there a way I can make it shorter? For example, do I actually need printf/scanf before each mean?

I also have no idea how to write the Harmoic code :/

Thanks 4 any help

2. You shouldn't ask for input, but use the same values for all three means (I would imagine). Do you have the formula for harmonic mean? (If not: the harmonic mean of x and y is 2xy/(x+y).)

3. Originally Posted by DJ_Steve
Hey

I'm currently stuck on a problem. I have to create a program that reads the input of two numbers and works out their Arithmetic/Geometric/Harmonic mean. It then calculates which mean is the highest and displays it on the screen.

This is what I have so far...

Code:
#include <math.h>

int main()
{
Double num1
Double num2
Double ari
Double geo
Double har

printf("enter num1");
scanf ("%d%*C" , &num1),

printf("enter num2");
scanf ("%d%*C" , &num2);

ari = ((num1+num2)/2);
printf("Arithmetic Mean =",ari);

printf("enter num1");
scanf ("%d%*C" , &num1),

printf("enter num2");
scanf ("%d%*C" , &num2);

geo = ((num1*num2)

printf("enter num1");
scanf ("%d%*C" , &num1),

printf("enter num2");
scanf ("%d%*C" , &num2);

har =

Is this correct so far? Is there a way I can make it shorter? For example, do I actually need printf/scanf before each mean?

I also have no idea how to write the Harmoic code :/

Thanks 4 any help
1. There's nothing as Double in C. C is case sensitive and you should change it to double.
2. For double the format specifier is %f not %d.
3. You can combine the scanf's in one as
Code:
scanf("%f%f",&num1,&num2);
4. I think the geometric mean is square root of num1*num2.

4. ok, I'll get working on that, thanks for the help

5. Code:
#include <math.h>

int main()
{
double num1
double num2
double ari
double geo
double har

printf("enter num1");
printf("enter num2");
scanf("%f%f",&num1,&num2);

ari = ((num1+num2)/2);
printf("Arithmetric Mean =",ari);

geo = sqrt(num1*num2)
printf("Geometric Mean =",geo);
}

return()
this is so hard! It keeps saying that num1, num2, geo, ari are all undeclared?! But I declare them at the start of the program? :/

6. Originally Posted by DJ_Steve
Code:
#include <math.h>

int main()
{
double num1
double num2
double ari
double geo
double har

printf("enter num1");
printf("enter num2");
scanf("%f%f",&num1,&num2);

ari = ((num1+num2)/2);
printf("Arithmetric Mean =",ari);

geo = sqrt(num1*num2)
printf("Geometric Mean =",geo);
}

return()
this is so hard! It keeps saying that num1, num2, geo, ari are all undeclared?! But I declare them at the start of the program? :/
Except of course, you don't. Maybe if you put semicolons where they belonged, you would.

7. Code:
#include <math.h>

int main()
{
double num1;
double num2;
double ari;
double geo;
double har;

printf("enter num1\n");
scanf ("%f%*C" , &num1);
printf("enter num2\n");
scanf ("%f%*C" , &num2);

ari = ((num1+num2)/2);
printf("Arithmetric Mean =\n",ari);

geo = sqrt(num1*num2);
printf("Geometric Mean =\n",geo);

return 0;
}
yay, I did it although at the moment the answers don't actually appear when I type in the 2 numbers

but at least I'm getting there!

Sorry about all these random questions but my tutor is no help and I pretty much have to learn everything from scratch by myself

8. Originally Posted by DJ_Steve
Code:
#include <math.h>

int main()
{
double num1;
double num2;
double ari;
double geo;
double har;

printf("enter num1\n");
scanf ("%f%*C" , &num1);
printf("enter num2\n");
scanf ("%f%*C" , &num2);

ari = ((num1+num2)/2);
printf("Arithmetric Mean =\n",ari);

geo = sqrt(num1*num2);
printf("Geometric Mean =\n",geo);

return 0;
}
yay, I did it although at the moment the answers don't actually appear when I type in the 2 numbers

but at least I'm getting there!

Sorry about all these random questions but my tutor is no help and I pretty much have to learn everything from scratch by myself
1. #include<stdio.h> is missing
2. Your printf statements are wrong. They should be like this.
Code:
printf("Arithmetric Mean =%f \n",ari); // change for geometric mean also
3. Why are you using %*C in your scanf?

9. oh the question said to put #include <math.h> and didn't even explain why, so I just did what it told me to do

I shall make the changes now

um, i dunno why I'm using %*C...i thought it was right lol ack

thanks 4 help

10. actually I just noticed I got rid of the %*C already, not sure why I had them in the first place

11. does anyone know why I would get the answer

Arimetic Mean = 1.#QNAN0
Geo Mean = 1.#QNAN0