Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will calculate the distance a vehicle travels. The distance

ID: 3654635 • Letter: W

Question

Write a program that will calculate the distance a vehicle travels. The distance a vehicle travels can be calculated as follows: distance = speed * time For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should then use a loop to display the total distance traveled at the end of each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled 1 40 2 80 3 120 Below is an example of what we are working on. We are using Scanf, Printf and returns. Please Help Consider the following for loop examples: A loop that will print the numbers from 1 to 100: #include int main(void) { int i; for (i=1; i<=100; ++i) { printf("%i ", i); } return 0; } A loop that will print the even numbers from 1 to 100: #include int main(void) { int i; for (i=2; i<=100; i=i+2) { printf("%i ", i); } return 0; } A loop that will print the even numbers from 200 to 300: #include int main(void) { int i; for (i=200; i<=300; i=i+2) { printf("%i ", i); } return 0; }

Explanation / Answer

/* Write a program that will calculate the distance a vehicle travels. The distance a vehicle travels can be calculated as follows: distance = speed * time For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should then use a loop to display the total distance traveled at the end of each hour of that time period. Here is an example of the output: What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hour Distance Traveled 1 40 2 80 3 120 */ #include using namespace std; int main() { int speed; int time; int distance; int i; printf("What is the speed of the vehicle in mph? "); scanf("%i", &speed); printf("How many hours has it traveled? "); scanf("%i", &time); printf("Hour Distance Traveled "); for (i=1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote