#!/bin/bash
# Function to calculate power using bc for floating-point numbers
calculate_power() {
base=$1
exponent=$2
result=$(echo "$base ^ $exponent" | bc -l)
echo "$base raised to the power of $exponent is: $result"
}
# Prompt the user for base and exponent
echo "Please enter the base (can be a floating-point number):"
read base
echo "Please enter the exponent (can be a floating-point number):"
read exponent
# Check if the inputs are valid numbers (integer or floating-point)
if [[ $base =~ ^-?[0-9]+(\\.[0-9]+)?$ ]] && [[ $exponent =~ ^-?[0-9]+(\\.[0-9]+)?$ ]]; then
# Call the function to calculate power
calculate_power "$base" "$exponent"
else
echo "Invalid input. Please enter valid numbers."
fi