write a program that reads in the radius of the circle and outputs one of the following depending on the user request:
1.circumference of the circle
2.area of the circle
3.diameter of the circle
pls phelp me.. i use c++ (printf and scanf). all of the given request (1-3)must have a formula. thanks in advance...
Can anyone help me in this program?urgently need it plss....?
The formulas needed are
Circumference of a circle is ( 2 ) * ( 3.1416 ) * radius
Area of a circle is ( 3.1416 ) * radius * radius
Diameter of a circle is ( 2 ) * radius
Your algorithm is:
Display a friendly greeting to the user
Prompt the user to enter 1 for circumference, 2 for area, 3 for diameter.
Accept the entry.
If the entry isn't 1, 2, or 3, repeat the prompt,
Prompt the user to enter the radius.
Accept the entry.
Use an "if" statement to determine which computation is requested, perform that computation, and display the answer.
Reply:Look, we should not do your homework for you. Also printf() and scanf() are C, not C++, but I'll offer you some formulas and a possible pseudocode soloution.
declare variables radius, diameter, pi (unless you are using a compiler which defines it, as some do) as floats.
Assign menu choice as int or char (doesn't matter which).
declare functions circumference and area as floats.
Assign pi 3.14.... as whatever is preferred. Input the radius. Assign diameter twice the radius.
Print out your menu. Input a choice. Use a switch statement to 1. call and print out the circumference statement (printf("The circumference is %f.\n", circumference(diameter, pi));) Circumference would only have to be a statement "return diameter*pi;". 2. call and print out area which would be "return pi*radius*radius;". 3. Print out diameter. default print out the menu and input a choice (no break statement after that one. It's your error checking.
Formulas are diameter=2*radius, Circumference =diameter*pi area=pi*radius^2 (radius squared). Hope that helps. But if it's an assignment you should be writing it yourself.
Reply:If you are still stuck, may be you can contact a C++ expert at websites like http://askexpert.info/ to code it for you.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment