LOOP Project; Distance = speed * times. Write a program that asks the user for w
ID: 3810923 • Letter: L
Question
LOOP Project; Distance = speed * times. Write a program that asks the user for write the speed of a vehicle (in miles per hour) and how many hours it has travelling. The program should then use a loop to display the distance the vehicle has travelled for each hour of that time period in miles and in kilometers. (1 mile = 14.6 km) in put validation the program should not accept negative numbers. output format the program should run as long as the user want show scenarios when the user enters in valid numbers for the speed or the distance.Explanation / Answer
I have executed in DEV C++
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
float time,speed;
do{
cout << "Enter speed in miles per Hour: ";
cin >> speed;
cout << "Enter time taken for travelling: ";
cin >> time;
cout << "DISTANCE MILES KILOMETERS ";
float i = 1.0;
while(i <= time){
cout << i*speed << " " << i*speed*1.6 << " ";
i = i + 1;
}
}while(time < 0.0 && speed < 0.0);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.