int rad;

int rad;
        float PI = 3.14 ,area,ci;
        printf("\n Enter radius of a circle:");
        scanf("%d",&rad);

        area = PI*rad*rad;
        printf("\narea of a circle is %f",area);
        ci = 2*PI*rad;
        printf("\ncircomeference  of a circle is %f",ci);       

Recommended Answers

All 2 Replies

so what's the problem?

One way to do this that looks a lot more like C++ code ...

// circle_calc101.cpp
// ask for radius of a circle and show area and circumference

#include <iostream>
#include <string>
#include <sstream>

int main(void)
{
    std::string response;
    float radius;
    float pi = 355.0/113;  // good approximation of pi

    // loop input until a number has been entered
    while(1)
    {
        std::cout << "Enter the radius: ";
        std::cin >> response;
        std::cin.ignore(1024, '\n'); // remove extra '\n'
        // convert to number using a stringstream
        std::istringstream convert(response);

        if ( convert >> radius )
        {
            break;
        }
    }
    std::cout << "radius of circle        = " << radius << std::endl;
    std::cout << "area of circle          = " << pi*radius*radius << std::endl;
    std::cout << "circumference of circle = " << 2*pi*radius << std::endl;

    std::cin.sync();  // purge any \n
    std::cin.get();   // console wait
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.