Mashetti A. answered 03/23/25
Expert Coding Tutor
#include <stdio.h>
#include <math.h>
int main() {
double radius, height, volume;
printf("Enter the radius of the can (cm): ");
if (scanf("%lf", &radius) != 1 || radius <= 0) {
printf("Error: Please enter a valid positive number for the radius.\n");
return 1; // Exit with error
}
// Get user input for height
printf("Enter the height of the can (cm): ");
if (scanf("%lf", &height) != 1 || height <= 0) {
printf("Error: Please enter a valid positive number for the height.\n");
return 1; // Exit with error
}
// Calculate volume
volume = PI * pow(radius, 2) * height;
// Display result
printf("The volume of the can is: %.2lf cubic cm\n", volume);
return 0; // Successful execution
}