350,352 views
29 votes
29 votes
A car dealership only sells cars that have fewer than 10 000 miles and are 5 years old or less. (i) Write an algorithm that will: • ask the user to enter the number of miles and the age of a car • validate the input to check that only sensible values that are in the given range are entered • output True if valid data has been entered or False if invalid data has been entered.

User Victor Marchuk
by
3.4k points

1 Answer

23 votes
23 votes

Answer:

Algorithm:

ValidateCarData (milesDrives, age)

Start

  • Prompt the user to enter the number of miles and the age of a car.
  • Get the input from the user.
  • Store the number of drives in the variable named milesDrives and the age of the car in the variable named age.
  • if ( milesDrives < 10000 and age <= 5)

Display true.

  • else

Display false.

Stop

Step-by-step explanation:

Algorithm: An algorithm is a step-by-step solution to a problem in a finite number of steps.

A car dealer sells only the car that

  • drives less than 10000 miles
  • and the age of the car is equal to or less than 5 years.

Prompt the user to enter the number of miles and the age of a car.

Validate the user-entered data.

when the user-entered data is valid (car drive fewer than 10000 miles and 5 years or less old)

Display true (user enters the valid data).

else (car drives more than 10000 miles or more than 5 years old)

Display false (user enters the invalid data).

User Tim MB
by
3.4k points