Question
Below is a piece of code that computes the distance traveled for a car. This code asks the user to input the total time, and
Below is a piece of code that computes the distance traveled for a car. This code asks the user to input the total time, and outputs the distance traveled. The user enters times until (s)he enters a non-negative number. This is done in a while loop.
Replace the while loop with a dowhile loop. The new code should work exactly the same way as the old, i.e. it should compute distance and print out the values of time and distance only if time entered is a non-negative number (including if a value <= 0 is entered the first time). Note, you may have to change code that lies outside the while loop (60 points)
You will write new code to account for acceleration using the formula , where d=v0t+(1/2)a(t^2), where d is distance, a is acceleration, and t is time. Now, you will ask for two inputs from the user, the first being time and the second being acceleration. Acceleration can be positive, negative, or zero, and it is a real (floating point or c type float) number, i.e. it can be fractional, e.g. 1.21. (40 points). You may use a while, dowhile, for loop or anything else in 2)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started