Ask Question
25 August, 16:00

Write a statement that increments (adds 1 to) one and only one of these five variables : reverseDrivers parkedDrivers slowDrivers safeDrivers speeders.

The variable speed determines which of the five is incremented as follows:

The statement increments reverseDrivers if speed is less than 0, increments parkedDrivers if speed is less than 1, increments slowDrivers if speed is less than 40, increments safeDrivers if speed is less than or equal to 65, and otherwise increments speeders.

+5
Answers (1)
  1. 25 August, 18:39
    0
    int reverseDrivers, parkedDrivers, slowDrivers, safeDrivers, speeders;

    int speed; / / variable declaration

    if (speed<0) / / checking condition

    reverseDrivers++; / / increment the value by 1

    else if (speed<1) / / checking condition

    parkedDrivers++; / / increment the value by 1

    else if (speed<40) / / checking condition

    slowDrivers++; / / increment the value by 1

    else if (speed<=65) / / checking condition

    safeDrivers + +; / / increment the value by 1

    else

    speeders++; / / increment the value by 1

    Explanation:

    Following are the description of statement

    Declared a variable reverseDrivers, parkedDrivers, slowDrivers, safeDrivers speeders and speed of integer types. These variables increments its value by 1 according to the condition of the speed variable. Speed variable check the condition of speed. if (speed<0) it increment the value by 1 in the "reverseDrivers" variable. if (speed<1) it increment the value by 1 in the "parkedDrivers" variable. if (speed<40) it increment the value by 1 in the "slowDrivers" variable. if (speed<=65) it increment the value by 1 in the "safeDrivers " variable. if all the if block condition fails then control moves to the else block and increment the value by 1 in the "speeders " variable.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a statement that increments (adds 1 to) one and only one of these five variables : reverseDrivers parkedDrivers slowDrivers ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers