![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2008
Posts: 9
Rep Power: 0
![]() |
Why am I not getting the correct output?
Intructions:
The program asks for the user to input the radius and height of a right cylinder. It then calculates surface area and volume of this cylinder and prints the out-put on the screen in the FORMAT GIVEN BELOW. The main program calls following three functions to accomplish the above job. calc_area (double rad, double height) calc_volume (double rad, double height) and print_info (void) II. Helpful Math Hints: Surface area = 2*PI*r*h + PI*r*r; and volume = PI * r*r*h III. Helpful Programming Hints: 1. Preprocessor define PI= 3.14159 2. Declare PROTOTYPE FUNCTIONS shown above with proper return parameters. 3. Define the three programs mentioned above, in region out-side your main program. 3. Declare variables r, d, h, V, A as “double”. 4. Ask user to enter r in centimeters, read the value and assign to r; ask to enter h in cms, read the value (scan in lf format) and assign to h. 5. Call the three programs, assigning their return values appropriately. 6. Using the results print the out-put. IV: Output to the screen in the format: __________________________________________________ ________________________ Enter diameter in centimeters: 3 Enter height in centimeters: 5 A right circular cylinder with a diameter = 3.00 cm and a height = 5.00 cm will have a volume and surface area VOLUME SURFACE AREA ------------------------------------------------------ 35.3429 cu_cm 61.2610 sq_cm Press any key to continue That is what I'm supposed to get... Here is my updated code: #include <stdio.h>
#include <math.h>
int main()
{
printf("My Name ID SA33\n");
printf("Class Number Spring 08\n");
printf("Homework 1 Jan 30, 2008\n\n\n");
double a,v,r;
double d;
double h;
double PI;
PI=3.14159;
printf("Enter diameter in centimeters: ");
scanf("%lf",&h);
printf("Enter height in centimers: ");
scanf("%lf",&d);
r= 0.5*d;
a= 2*PI*r*h + PI*r*r;
v= PI*r*r*h;
printf("With a diameter of %lf cm and a height of %lf cm\n",d,h);
printf("The volume will be %lf cu_cm and the surface area will be %lf sq_cm\n\n",v,a)
;
return 0;
}Here is the output I got: My Name ID SA33 Class Number Spring 08 Homework 1 Jan 30, 2008 Enter diameter in centimeters: 3 Enter height in centimers: 5 With a diameter of 5.000000 cm and a height of 3.000000 cm The volume will be 58.904812 cu_cm and the surface area will be 66.758788 sq_cm Press any key to continue . . . So why am I not getting the correct output here? I can't figure out where my problem is. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Re: Why am I not getting the correct output?
Please use your old thread, which had the same assignment posted, to ask further questions next time.
printf("Enter diameter in centimeters: ");
scanf("%lf",&h);
printf("Enter height in centimers: ");
scanf("%lf",&d);You have &h and &d in the wrong places. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2008
Posts: 9
Rep Power: 0
![]() |
Re: Why am I not getting the correct output?
Sorry for posting a new topic, but I wrote a whole new program so that's why I switched topics.
That was my problem btw. Thank you for the help. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is wrong with this Output Statement | kewlgeye | Visual Basic | 2 | Jan 25th, 2008 10:46 PM |
| advanced user output | l2u | C++ | 6 | May 9th, 2007 8:16 PM |
| Change the name of output file | jazz | C | 4 | Jun 28th, 2006 2:54 AM |
| Numerical data output to a file | can342man | C++ | 4 | Jan 27th, 2006 4:21 PM |
| It's giving me "Press any key to continue" and no other output.. | Insomniac | C | 15 | Jun 5th, 2005 7:07 AM |