Question

In: Computer Science

Write a while loop to ask the user to type number of hours(double) they work per...

Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input.

If number of hours is greater than 0 and less than 5, then:  salary = numberofhours * 12, loop continues, the user can type another number

If number of hours is greater or equal to 5, and less than 12, then: salary = numberofours * 14, loop continues, the user can type another number

If number of hours is greater or equal to 12, and less than 24, then salary = numberofours * 16, loop continues, the user can type another number

If number of hours is negative or greater than 24, then the loop stops, message "Invalid Input" will be printed.

Solutions

Expert Solution

Dear student,

Let us code the above-asked loop using C programming language as no specific language is mentioned. We can use any language but the logic will remain the same. We are assuming 0 is included in the 0 to 5 hours segment as there is nothing specified for it.

The while loop is in Bold.

#include <stdio.h>

int main()
{
double hours=1.0;// any value just to enter the loop for the first time

double sal=0.0;

while(hours>=0 && hours<24)

{

printf("\nEnter the number of hours you work per day: ");

scanf("%lf", &hours);

if(hours>=0 && hours<5)

{

sal=hours*12;

printf("\nYour salary is: %lf",sal);

}

else if(hours>=5 && hours<12)

{

sal=hours*14;

printf("\nYour salary is: %lf",sal);

}

else if(hours>=12 && hours<24)

{

sal=hours*16;

printf("\nYour salary is: %lf",sal);

}

else

{

printf("\nInvalid Input");

break; //this command ends the loop

}

}//while loop ends

return 0;
}

I hope the above answer solves your doubt.

Don't forget to give it a thumbs up.

Regards


Related Solutions

in java Write a while loop to ask the user to type number of hours(double) they...
in java Write a while loop to ask the user to type number of hours(double) they work per day. Calculate and print the salary for each valid input. If number of hours is greater than or equal to 0 and less than 5, then:  salary = numberofhours * 5, loop continues, the user can type another number If number of hours is greater or equal to 5, and less than 10, then: salary = numberofours * 8, loop continues, the user...
Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
Write a Python program that has a loop to continuously ask the user for a number,...
Write a Python program that has a loop to continuously ask the user for a number, terminating the loop when the number entered is -1. Inside the loop, 1.) display one asterisk(*) if the number is 1, 2.) two asterisk(**) if the number is 2 and 3.) "OTHER" if the number is any other number.
Python Programming Please! #Name: #Date: #Random number, loop while true #ask user for number. Check to...
Python Programming Please! #Name: #Date: #Random number, loop while true #ask user for number. Check to see if the value is a number between 1 and 10 #if number is too high or too low, tell user, if they guessed it break out of loop Display "Welcome to my Guess the number program!" random mynumber count=1 while True try Display "Guess a number between 1 and 10"   Get guess while guess<1 or guess>10 Display "Guess a number between 1 and...
7. Ask the user to type in a number and compare this number with 8. The...
7. Ask the user to type in a number and compare this number with 8. The user could try twice. If the first user input was 8 then print out “Correct!” and terminate the program, otherwise ask user to type in a number for the second time. If the second input was 8 then print out “Correct”, otherwise print “Game over!” Finish the assembly code segment for the above requirement. .data message: .asciiz "Please enter a random number:" right_str: .asciiz...
Ask the user how many days that they collected gems. A loop you write should loop...
Ask the user how many days that they collected gems. A loop you write should loop how many days the user enters. If the user enters 5 days, then the loop should loop 5 times to collect the data from each day. So, each loop iteration represents a day. In each loop iteration, ask the user how many gems they collected that day. After the loop finishes gathering the data for each day, calculate the total and average gems collected....
​​​​​​​For java program. Write a while loop that will let the user enter a series of...
​​​​​​​For java program. Write a while loop that will let the user enter a series of integer values and compute the total values and number of values entered. An odd number will stop the loop. Display the number of iterations and the total of the values after the loop terminates. for Loop Write a for loop to display all numbers from 13 - 93 inclusive, ending in 3. Write a for loop to display a string entered by the user...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
in java code Modify your program as follows: Ask the user for the number of hours...
in java code Modify your program as follows: Ask the user for the number of hours worked in a week and the number of dependents as input, and then print out the same information as in the initial payroll assignment. Perform input validation to make sure the numbers entered by the user are reasonable (non-negative, not unusually large, etc). Let the calculations repeat for several employees until the user wishes to quit the program. Remember: Use variables or named constants...
In python Write the code to ask a user to enter a number in the range...
In python Write the code to ask a user to enter a number in the range of 1-100. Have the code checked to make sure that it is in this range. If it is not, let the user re-enter the number. The user should be able to re-enter numbers until the number is within the correct range.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT