void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
Serial.println("Enter the first number (myNum1):");
}
void loop() {
// Check if the user has entered data
if (Serial.available() > 0) {
// Read the first number entered by the user
int myNum1 = Serial.parseInt();
Serial.parseInt();
Serial.print("You entered: ");
Serial.println(myNum1);
// Prompt for the second number
Serial.println("Enter the second number (myNum2):");
// Wait for user input for the second number
while (Serial.available() == 0) {
// Wait until the user enters the second number
}
// Read the second number entered by the user
int myNum2 = Serial.parseInt();
Serial.parseInt();
Serial.print("You entered: ");
Serial.println(myNum2);
// Call multiplyNumbers with the user-provided values
int result = multiplyNumbers(myNum1, myNum2);
// Print the detailed result message
Serial.print(myNum1);
Serial.print(" multiplied by ");
Serial.print(myNum2);
Serial.print(" is ");
Serial.println(result);
// Add a delay to allow the user to see the result
delay(5000); // 5-second delay
Serial.println("\nEnter the first number (myNum1):");
}
}
int multiplyNumbers(int a, int b) {
return a * b; // Return the result of multiplying a and b
}