180k views
4 votes
Powershell

Given revenue below is the revenue collected in a business in 5 business day week.

[double] $revenue = 47334.72

Average Daily Revenue = 9466.94

Write powershell statements to print the above 'Average Daily Revenue'

Note: You cannot hard code the Average Daily Revenue number.
You Must calculate using the given variable $revenue
Also note that the Average Daily Revenue be printed in a 8-width field with 2 places precision.

User Birderic
by
7.6k points

1 Answer

1 vote

Final answer:

To calculate Average Daily Revenue in PowerShell, divide the total revenue by the number of days and format the output using PowerShell's -f operator to meet the specific print requirements.

Step-by-step explanation:

To calculate the Average Daily Revenue using the $revenue variable in PowerShell, you'll first need to divide the total revenue by the number of business days in the week which we know is 5. After that, to comply with the requirements of printing the average in an 8-width field with 2 places of precision, you can use the -f format operator. Below is the PowerShell statement that performs these calculations:

$revenue = 47334.72
$daysInWeek = 5
$averageDailyRevenue = $revenue / $daysInWeek
Write-Host ('{0,8:N2}' -f $averageDailyRevenue)

This will output the Average Daily Revenue in the desired format.

User Asel
by
7.9k points

No related questions found