# C++ Programming Code Examples

## C++ > Computer Graphics Code Examples

### program to find area of circle using functions

``` program to find area of circle using functions User enter radius or diameter of circle. Program should have two functions one which takes radius as parameter and second takes diameter as parameter. If user enters wrong option then tell users its valid selection and chose again the right option. #include <iostream> #define PI 3.14159 using namespace std; float AreaOfCircle(float radius); float AreaWithDiameter(float diameter); int main() { float radius,diameter,circleArea; char choice='0'; cout<<"\n\t\t\tFind Area Of Circle:"<<endl; for(;choice!='1'&&choice!='2';) { cout<<"\nEnter 1 to Enter Radius OR 2 to Enter Diameter: "; cin>>choice; if(choice!='1'&&choice!='2') cout<<"\n\t\tEnter a VALID Option "; } if(choice=='1') { cout <<"\n\t\tEnter Radius To Find Area: "; cin>>radius; circleArea=AreaOfCircle(radius); } else if(choice=='2') { cout <<"\n\t\tEnter Diameter To Find Area: "; cin>>diameter; circleArea=AreaWithDiameter(diameter); } cout<<"\n\n\t\tArea of Circle is:->> "<<circleArea<<endl; return 0; } float AreaOfCircle(float radius) { return (PI*(radius*radius)); } float AreaWithDiameter(float diameter) { return (AreaOfCircle(diameter/2)); } ```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5048009,"math_prob":0.7628649,"size":1276,"snap":"2020-45-2020-50","text_gpt3_token_len":315,"char_repetition_ratio":0.16194968,"word_repetition_ratio":0.051282052,"special_character_ratio":0.27586207,"punctuation_ratio":0.15789473,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9823782,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-25T14:08:02Z\",\"WARC-Record-ID\":\"<urn:uuid:6e104b3d-1c9f-4f69-87b0-621910fabae3>\",\"Content-Length\":\"13752\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6f95fab9-80cf-4492-80b0-190ef2d92996>\",\"WARC-Concurrent-To\":\"<urn:uuid:bb4587a8-9b5f-44fd-a812-83fea23ad3e0>\",\"WARC-IP-Address\":\"209.126.5.95\",\"WARC-Target-URI\":\"https://cplusplus.happycodings.com/computer-graphics/program-to-find-area-of-circle-using-functions.html\",\"WARC-Payload-Digest\":\"sha1:HW6XMED72IUKUPNNUOYWTZU7J4VPBF6E\",\"WARC-Block-Digest\":\"sha1:LBHJ6P3WOFYJPWKLWD4RV4HBOSHLJ767\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141182794.28_warc_CC-MAIN-20201125125427-20201125155427-00357.warc.gz\"}"}