# Thread: Need help in C

1. ## Need help in C

Hi all,
I am new in programming with C. Will you please help me to solve the following problem:

I want a program whose function is to enter the volume of a sphere 'x' and the program has to find out the unknown radius of the sphere and when the program finds radius, the program has to tell you if the sphere can go through the pipe or not.

Code:
```#include <stdio.h>

void main ()

{
float a,b;
printf("If you have a sphere with a volume of 'x', will it fit in a pipe with a radius of 5cm ??\n\n");
printf("Enter volume 'x': ");
scanf("%f",&a);
printf("The radius of the shpere is: %f\n\n",((a*3)/(4*3.142))^0.333);
b= ((a*3)/(4*3.142))^0.333;

if (b>5)
{printf("The sphere will not fit in the pipe.\n\n\n\n");}
else if (b<5)
{printf("The sphere will fit in the pipe.\n\n\n\n");}
else
printf("The sphere will fit in the pipe tightly.\n\n\n\n");}
}```

2. Hi Drinu1232, fist use code tags... read the link you went by before this forum...

You'll get help quickly that way. Also, If you should be able to "edit" your post,
insert the code tags, then go on from there. Welcome to the board!

3. Originally Posted by drinu1232
Hi all,
I am new in programming with C. Will you please help me to solve the following problem:

I want a program whose function is to enter the volume of a sphere 'x' and the program has to find out the unknown radius of the sphere and when the program finds radius, the program has to tell you if the sphere can go through the pipe of not.
From your posted source code...

You need to look up the caret ( ^ ) operator I don't think it does what you think it does.

Move the calculation of b above your first printf() and have printf print b instead of doing the math twice. It will also give you confirmation that b is calculated correctly.

There's no need for multiple ifelse structure. The sphere either fits or it doesn't...
Code:
```if (b < 5)
printf("it fits");
else
printf(it don't fit");```
Also please use code tags when posting your code to the forum.

4. Originally Posted by CommonTater
From your posted source code...

You need to look up the caret ( ^ ) operator I don't think it does what you think it does

so what can i use instead of ^ ??

Can someone please fix the error for me since i can hardly understand a thing from what you are saying :O (im still a beginner)

thx in advance

5. Originally Posted by drinu1232
so what can i use instead of ^ ??
pow from <math.h>

6. Originally Posted by laserlight
pow from <math.h>
so is have to write '#include <math.h>' under '#include <stdio.h>' ??
... and type 'pow' instead of '^' ??

thx

7. Originally Posted by drinu1232
so is have to write '#include <math.h>' under '#include <stdio.h>' ??
... and type 'pow' instead of '^' ??

thx
Yes, you need to include the math.h file. The pow(x,y) as laserlight suggested,
in most compilers, expect type doubles.

Btw, I modified your program and got it working aprox. 10 mins after your post.

You have to show some effort in this. There are many people here that can
help you, but you should look at some of the FAQ's on this board. There is
a wealth of information there. :-)

8. i wrote #include <math.h> under #include <stdio.h> and pow instead of ^ , and the program is still giving me an error :S pls need help!!

9. Originally Posted by drinu1232
i wrote #include <math.h> under #include <stdio.h> and pow instead of ^ , and the program is still giving me an error :S pls need help!!
1) No mention of what error you are getting.
2) No update of what your code looks like.

10. These are the errors/warnings that i am getting:

(11) : error C2143: syntax error : missing ';' before 'constant'
(11) : warning C4550: expression evaluates to a function which is missing an argument list
(11) : error C2059: syntax error : ')'
(12) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
(12) : error C2143: syntax error : missing ';' before 'constant'
(12) : warning C4550: expression evaluates to a function which is missing an argument list

My problem is that i never used the <math.h> before.... and i dont know what the above errors are referring to.

Code:
```#include <stdio.h>
#include <math.h>

void main ()

{
float a,b;
printf("If you have a sphere with a volume of 'x', will it fit in a pipe with a radius of 5cm ??\n\n");
printf("Enter volume 'x': ");
scanf_s("%f",&a);
printf("The radius of the shpere is: %f\n\n",((a*3)/(4*3.142))pow 0.333);
b=((a*3)/(4*3.142))pow 0.333;

if (b>5)
{printf("The sphere will not fit in the pipe.\n\n\n\n");}
else if (b<5)
{printf("The sphere will fit in the pipe.\n\n\n\n");}
else
{printf("The sphere will fit in the pipe tightly.\n\n\n\n");}
}```

11. pow() is a function.
Call it like you call every other function.
math.h man page

12. Originally Posted by drinu1232
i wrote #include <math.h> under #include <stdio.h> and pow instead of ^ , and the program is still giving me an error :S pls need help!!

How To Use pow(x,y)

13. Aaaannnnnddd...another selfish crossposter.

14. Originally Posted by rags_to_riches
LMAO, RtR you mean all this time? I need to be demoted from the cross post
team here - or at least get a demerit. Also, I'll have to bring this up with my priest during my next confession.

15. Originally Posted by Salem
pow() is a function.
Call it like you call every other function.
math.h man page
I just noticed this link. Bookmarked. So it turns out now, this thread
wasn't a complete waste of my time.

Popular pages Recent additions