183k views
3 votes
2.3 Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Use 35 hours and a rate of 2.75 per hour to test the program (the pay should be 96.25). You should use input to read a string and float() to convert the string to a number. Do not worry about error checking or bad user data.

1 Answer

7 votes

Answer:

The programming language is not stated; However this program will be written using Python programming language

Comments are not used; See Explanation Section for line by line explanation of the code

hours = float(input("Hours: "))

rate = float(input("Rate per hour: "))

pay = hours * rate

print(pay)

Step-by-step explanation:

The first line of the code prompts the user for hour.

The input is converted from string to float

hours = float(input("Hours: "))

The next line prompts the user for hour.

It also converts input from string to float

rate = float(input("Rate per hour: "))

Pay is calculated by multiplying hours by rate; This is implemented using the next line

pay = hours * rate

The calculated value of pay is displayed using the next line

print(pay)

When the program is tested by the given parameters in the question

hours = 35

rate = 2.75

The printed value of pay is 96.25