# Thread: Finding volume of cone error help!

1. ## Finding volume of cone error help!

So my code runs but the problem is that the radius is always 0! Not sure what the problem is tried changing it to double and int and still won't work any help would be appreciated! I have attached the source codes below for you guys to see Btw boss.c is my header the calling program and iff.h is my source code.
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <math.h>

#include "screen.h"
#include "iffs.h"

int main()
{
ClearTheScreen();

PauseTheScreen();

Heading();

TriangleArea(10,20,2,5,7);

VolumeOfSphere(12,20,5);

VolumeOfCone(14,20,8,10);

Footer();

}```
Code:
```void TriangleArea(int row, int col, double a, double b, double c)
{
double Area;
_settextposition(row,col);

Area = a + b + c / 2;

Area = Area * (Area - a) * (Area - b) * (Area - c);

Area = sqrt(Area);
printf("The area of a triangle with sides 2, 5, 7 = %.3f",Area);
}
void VolumeOfSphere(int row, int col, int sun)
{
int Volume;
_settextposition(row,col);

Volume = 4/3 * 3.14159 * sun * sun * sun;
printf("Volume of sphere with radius %2d = %2d", sun, Volume);
}
void VolumeOfCone(int row, int col, int star, int moon)
{
int Volume;
_settextposition(row,col);

Volume = (1/3) * 3.14159 * star * star * moon;
printf("Volume of cone with radius %d height %d = %d",Volume,star,moon);
}```

2. > Volume = (1/3) * 3.14159 * star * star * moon;
1/3 is done in integer arithmetic.

Try 1.0 / 3.0

3. Oh no wonder! Ok, it works now thank you!

4. You shouldn't put the actual implementations in your header file. Usually you only put the function prototypes in the header file and define the functions in a source file (.c) with the same name.

Thus your "iffs.h" should look like:
Code:
```#ifndef IFFS_H  // to protect the header file to be
#define IFFS_H  // included more than once in your project

void TriangleArea(int row, int col, double a, double b, double c);
void VolumeOfSphere(int row, int col, int sun);
void VolumeOfCone(int row, int col, int star, int moon);

#endif```
and your "iffs.c" should look like:
Code:
```#include <stdio.h> // always include every header you want to use in your
#include <math.h>  // source file (you will need another one for "_settextposition")

#include "iffs.h"  // always include the prototypes to allow the compiler to check them with your definitions

void TriangleArea(int row, int col, double a, double b, double c)

{
// here come the definitions of your functions
// ...```
You have to include "iffs.h" in "boss.c" too.

Bye, Andreas

5. You have the same problem with 4/3, which is simply 1.

Popular pages Recent additions