Practice Break Solutions

#include <stdio.h>
#include <sysexits.h>
#include <math.h>

int     main(int argc,char *argv[])

{
    double  radius;
    
    // Use fputs() rather than printf() to avoid scanning for format specifiers
    fputs("Please enter the radius of the sphere: ", stdout);
    if ( scanf("%lf", &radius) != 1 )
    {
        fputs("Error: Input is not a number.\n", stderr);
        return EX_DATAERR;
    }
    if ( radius <= 0 )
    {
        fprintf(stderr, "Error: Radius %f is less than 0.\n", radius);
        return EX_DATAERR;
    }
    printf("Surface area = %f\n", 4.0 * M_PI * radius * radius);
    printf("Volume       = %f\n", 4.0 / 3.0 * M_PI * radius * radius * radius);
    return EX_OK;
}