logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/cs256su21code/jun10/circle.c

/*

we've combined our area and circumference programs into one program
we also made functions for finding the area and circumference of the circle


also, we made a void function that handles all the circle related stuff

and put it in an infinite loop
*/


#include <stdio.h>
#include "circle.h"

void circleInfo(double radius);


int main(){

	double radius; //because now we want radius to handle decimals
    int rt;

	printf("Enter the radius: ");
    scanf("%lf", &radius); //since radius is a double , we need the %lf signifier for scanf 
                           // to be able to read doubles  

    
    for(;;){ //this loop will run until rt is not 1

        circleInfo(radius);

        printf("\nWould you like to enter another radius?\n");
        printf("Enter a number if yes, any letter if no:\nRadius: ");
        rt = scanf("%lf", &radius);//getting the return value of scanf

        if(rt != 1) //if scanf doesn't return 1 (in this case, it doesn't read a number, break the loop)
            break;


    }

 
    return 0;

}

void circleInfo(double radius){


    if(radius < 0){
        printf("Error: Please enter a positive number\n");
        return;
    }


    double area, circumference;

    area = areaCircle(radius);
    //both these functions are defined in circle.h
    circumference = circumCircle(radius);

    printf("Radius of Circle: %f\n", radius);
    printf("Area: %f, Circumference: %f\n", area, circumference);

    //void functions don't return values, so we don't need a return statement
    // though if you need to end the function early, like in the if statement above
    // you can use return, but don't put anything other than a semi-colon after it.

}