Question

Please help me to try to better understand how to write an algorithm and then write...

Please help me to try to better understand how to write an algorithm and then write the code in C language.

Create a flowchart for the design to perform the following task and then implement a program that computes the distance traveled by a car moving at a constant speed for a specific amount of time. This program must understand different units of measurement for speed, time, and distance.

The algorithm will ask the user for the following information:

  1. The speed at which the car is traveling.
  2. The units of the speed value provided in (1). Use the "menu" command to provide the following options: miles per hour, kilometers per hour, meters/second, feet/minute
  3. The time that the car has been traveling at the indicated speed.
  4. The units of the time value provided in (2). Prompt the user to choose one of the following options: seconds, minutes, hours, days.
  5. The units in which to display the answer. Prompt the user to choose one of the following options: miles, kilometers, meters, feet and display the answer in the requested units.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

int main()
{
float timee,distance,speed;
int timeunit,speedunit;
printf(" Enter speed : ");
scanf("%f",&speed);
printf(" Select the unit of speed\n 1.Miles/hr \n 2.KM/hr \n 3.Meters/second\n 4.Feet/minute : ");
scanf("%d",&speedunit);
// We will convert all speeds to km/hr
switch(speedunit)
{
case 1: speed=1.60934*speed;
break;
case 2: break;
case 3: speed=speed*3.6;
break;
case 4: speed=speed/54.681;
break;
}
printf(" Enter Time : ");
scanf("%f",&timee);
printf(" Select the unit of time\n 1.Seconds \n 2.Minutes \n 3.Hours\n 4.Days : ");
scanf("%d",&timeunit);
// We will convert all times to hours
switch(timeunit)
{
case 1: timee/=3600;
break;
case 2: timee/=60;
break;
case 3: break;
case 4: timee*=24;
break;
}
distance=speed*timee;
printf(" Select the unit of distance you want\n 1.Miles \n 2.Kilometers \n 3.Meters\n 4.Feet : ");
scanf("%d",&timeunit);
// We will convert all times to hours
switch(timeunit)
{
case 1: distance/=1.609;
break;
case 2:
break;
case 3: distance*=1000;
break;
case 4: distance*=3280.84;
break;
}
printf("Distance = %f",distance);
}

Now i will tell you how to write this algorithm.

So basically in this question you have to find the distance from given speed and distance, now the only problem is units, you need to convert the units for the appropriate results.

Algorithm

Step 1: Read speed from user.

Step 2: Now ask from the menu the units of speed

Step 3: Now for the given units we will convert the speed to km/hr.

Step 4: Now ask for time and units

Step 5: Now we will convert the time to hours

Step 6: Now we will calculate the distance by multiplying speed and time.

Step 7: Now we'll ask for the required units for distance and will convert to required unit with formula.

Step 8: Print distance and exit.

C Please Help Me To Try To Better x 5 Online C Compiler - online editor X G kilometer to miles - Google Sear x G meter/sec to km/hr - Google Sea x + -ox f = c onlinegdb.com/online_c_compiler Run Debug Stop Share Save {} Beautify Online GDB beta Language C online compiler and debugger for c/c++ main.c 1 #include <stdio.h> code. compile. run, debug. share. int main() IDE My Projects OO van pw Learn Programming Programming Questions float timee, distance, speed; int timeunit, speedunit; printf(" Enter speed : "); scanf("%f", &speed); printf(" Select the unit of speed\n 1.Miles/hr In 2.KM/hr In 3.Meters/second\n 4.Feet/minute : "); scanf("%d", &speedunit); // We will convert all speeds to km/hr switch(speedunit) Opportunity for Intern Sign Up 12 Login f y + 28.3K + 28.3K case 1: speed=1.60934* speed; break; case 2: break; 16 input DigitalOcean 1. Seconds 2.Minutes 3.Hours 4.Days : 4 Select the unit of distance 1. Miles 2. Kilometers 3.Meters 4. Feet : 1 Distance = 58332.320312 DigitalOcean Test out the most developer- friendly cloud platform with a $50 credit. ads served ethically About - FAQ - Blog – Terms of Use . Contact Us ...Program finished with exit code o • GDB Tutorial - Credits . Privacy Press ENTER to exit console. © 2016-2019 GDB Online 1 Type here to search o tema 9 ^ ¢J 11:33 1) ENG 06-10-2019

Add a comment
Know the answer?
Add Answer to:
Please help me to try to better understand how to write an algorithm and then write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please have it written in Python. The distance a vehicle travels can be calculated as follows:...

    Please have it written in Python. The distance a vehicle travels can be calculated as follows: distance 5 speed 3 time For example, if a train travels 40 miles per hour for three 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 the number of hours it has traveled. It should then use a loop to display the distance the vehicle has traveled for...

  • The distance a vehicle travels can be  calculated as follows: distance = speed * time. For...

    The distance a vehicle travels can be  calculated as follows: distance = speed * time. For example, if a train travels 40 miles per hour for three hours, the distance traveled is 120 miles. Write a program using python that asks the user for the speed of a vehicle in mph and the number of hours it has traveled. It should then use a while loop to display the distance the vehicle has traveled for each hour of that time...

  • programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and...

    programming in Microsoft visual studio. Write a C++ program for the following algorithm. Compile, run, and verify the result by choosing some test data. Prompt user to write X1 value in double Read X1 Prompt user to write X2 value in double Read X2 Prompt user to write Y1 value in double Read Y1 Prompt user to write Y2 value in double Read Y2 Compute the lengths of the two sides of the right triangle generated by the two points...

  • PLEASE HELP WITH CODE PYTHON BASE.!!!!!!!! Tasks: Complete the following programs noted below: Problem 1: A...

    PLEASE HELP WITH CODE PYTHON BASE.!!!!!!!! Tasks: Complete the following programs noted below: Problem 1: A painting company has determined that for 112 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $35.00 per hour for labor. Write a program that asks the user to enter the square feet of wall space to be painted and the price of paint per gallon. The program should display the following data:...

  • Please help, I don’t really understand Answer the following questions. 1) Find the constant rate of...

    Please help, I don’t really understand Answer the following questions. 1) Find the constant rate of change What is the constant rate of change for textbooks per student? NUMBER OF TEXTBOOKS Number of Students Number of Textbooks 14 21 28 35 70 105 140 Change in students: Change in textbooks Constant rate of change: 3) Find the constant rate of change What is the constant rate of change in miles traveled for each hour? DISTANCE TRAVELED Distance Traveled Time (hours)...

  • Tasks: Complete the following programs noted below: Problem 1: A painting company has determined that for...

    Tasks: Complete the following programs noted below: Problem 1: A painting company has determined that for 112 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $35.00 per hour for labor. Write a program that asks the user to enter the square feet of wall space to be painted and the price of paint per gallon. The program should display the following data: The use of functions is required....

  • Practice Problem [no points]: You should read and understand Fibonacci algorithm, write a code in a...

    Practice Problem [no points]: You should read and understand Fibonacci algorithm, write a code in a high level language of your choice and in Assembly to find a Fibonacci number and check your result. At the end of this assignment a possible solution to this problem is given both in Python and MIPS assembler. Note that it would have been possible to write the Python differently to achieve the same function. . [20 points] Write and debug a MIPS program...

  • USING PYTHON IDLE 3.4: NEED HELP WITH THIS PLEASE! :( Question #8: You want to determine...

    USING PYTHON IDLE 3.4: NEED HELP WITH THIS PLEASE! :( Question #8: You want to determine the distance to lightning strikes during a storm. This can be measured using the time elapsed between seeing the lightning flash and hearing the thunder. You know that the speed of sound is approximately 1,100 ft/second and 1 mile is 5,280 feet. Write a program named q8.py that prompts the user for the number of lightning strikes to analyze and the number of seconds...

  • Solve the following using the 5-step process. The speed of a freight train is 75 mph...

    Solve the following using the 5-step process. The speed of a freight train is 75 mph slower than the speed of a passenger train. The freight train travels 340 miles in the same time that it takes the passenger train to travel 490 miles. Find the speed of each train. Instructions: Enter your answer as a whole number, fraction, or radical. When entering units, type without capitals e.g. mph, feet, meters, yards, etc. The freight train is travelling at Number...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT