131k views
1 vote
You need to plan a road trip. you are traveling at an average speed of 40 miles an hour.

given a distance in miles as input (the code to take input is already present), output to the console the time it will take you to cover it in minutes.

sample input:
150

sample output:
225

explanation: it will take 150/40 = 3.75 hours to cover the distance, which is equivalent to 3.75*60 = 225 minutes.

kindly assist in writing of this code.

User Snochacz
by
6.6k points

1 Answer

1 vote

Python:

#Distance variable

mile = int(input("Enter the distance: "))

#Print the result.

print(f"Estimated time: {(mile/40)*60} minutes.")

C++:

#include <iostream>

int main(int argc, char* argv[]) {

//Distance variable.

int mile;

//Get input.

std::cout << "Enter the distance: ";

std::cin >> mile;

//Print the result.

std::cout << "Estimated time: " << (double(mile)/40.0)*60 << " minutes." << std::endl;

return 0;

}

Java:

import java.util.*;

class Distance {

public static void main(String[] args) {

//Scanner object

Scanner s = new Scanner(System.in);

//Distance variable.

double mile;

//Get input.

System.out.print("Enter the distance in mile: ");

mile = s.nextDouble();

//Print the result.

System.out.println("Estimated time: " + (mile/40)*60 + " minutes.");

}

}

You need to plan a road trip. you are traveling at an average speed of 40 miles an-example-1
You need to plan a road trip. you are traveling at an average speed of 40 miles an-example-2
You need to plan a road trip. you are traveling at an average speed of 40 miles an-example-3
User Ingo Kegel
by
6.3k points