Purpose. The purpose of this lab is to perform a calculation repetitively within a loop. The loop may be either a while loop or a for loop. You are to write a program that calculates the distance a vehicle has traveled in a certain number of hours. Write a program called vehicleTrip.cpp to calculate the distance traveled for a given speed. Requirements. 1. Using the following formula: distance rate * time = calculate how many miles a vehicle has travelled in a certain number of hours.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
The
The program doesn't work properly. if we input 40 for the first question (What is the speed of the vehicle in mph?) and 3 for the second ( How many hours has it traveled?). The ouput should be something 1 40 , which is not.
2 80
3 120