Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C code program help. I am trying to find the volume of a cylinder. This is what I have so far. It does run, it

C code program help.

I am trying to find the volume of a cylinder. This is what I have so far. It does run, it does ask for numbers. But it doesn't calculate correctly. For example for radius I would put in 4.5, and height 4. It tells me that the answer is 144.00. I calculated it to be 254.47. I also tried 3, and 4 for radius and height and it tells me 108.00. I calculated it to be 113.1. Best I can figure is it is just taking the whole numbers and using those. At least for the last example.

I have tried several combinations of putting different data types in both main.c and the rest of it.

Any help or ideas would be helpful. Thank you.

(There are other questions that were in the code but I have deleted it before posting. So there might be some random code still left in here. But I tried really hard to comment out everything but the part I was working on. )

#define _CRT_SECURE_NO_WARNINGS #include #include #include

#define PI 3.141592

int main(void) { //Cylinder double radius = 0.0, height = 0.0; double pi3 = PI; double volume = 0.0; pi3 = get_pi3(); radius = get_number3(); height = get_number4(); volume = calculate_volume(pi3, radius, height); display_volume(volume); }

//Cylinder Stuff get_pi3() { double pi3 = PI; return pi3; }

get_number3(void) { double number3 = 0.0; printf("Please enter the radius of your cylinder: "); scanf("%lf", &number3);

return number3; }

int get_number4(void) { double number4 = 0.0; printf("Please enter the height of your cylinder: "); scanf("%lf", &number4);

return number4; }

calculate_volume(double radius, double height, double pi3) { double volume = 0.0; volume = (double)((pow(radius, 2))*height*pi3); return volume; }

display_volume(double volume) { printf("The volume is: %.2lf ", volume); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

101 Database Exercises Text Workbook

Authors: McGraw-Hill

2nd Edition

0028007484, 978-0028007489

More Books

Students also viewed these Databases questions