void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
while(!Serial){continue;}
Serial.println("Enter the radius of the circle:");
}
void loop() {
if (Serial.available() > 0) {
float radius = Serial.parseFloat();
float area = calculateCircleArea(radius);
Serial.print("The area of a circle of radius ");
Serial.print(radius);
Serial.print(" is: ");
Serial.println(area, 2); // Print area with two decimal places
Serial.println("Enter another radius:");
}
// process newline characters from pressing enter key
while (Serial.available() > 0) {
char c = Serial.read();
if (c == '\n' || c == '\r') {
break; // Exit the loop when newline or carriage return is found
}
}
}
// User-defined function to calculate the area of a circle
float calculateCircleArea(float r) {
float area = PI * r * r;
return area;
}