You have decided to enter a model boat race. You put your boat at the start line next to your
best friend Jill’s boat. Create a program to print out the distance that both of your boats
travelled given the speed your boat travels in (feet per minute), the speed that Jill’s boat
travels and the number of minutes in the race.
Distance = speed * time
Use the following as your sample Data:
speedMe = 6.2
speedJill = 5.9
time = 2
distanceMe = speedMe * time = 6.2 * 2 = 12.4
distanceJill = speedJill * time = 5.9 * 2
Algorithm:
Start
Declare variable speedMe
Declare variable speedJill
Declare variable time
Declare variable distanceMe
Declare variable distanceJill
Get the speed your boat travels in (feet per minute) (speedMe) from the keyboard
Get the speed Jill's boat travels in (feet per minute) (speedJill) from the keyboard
Get the number of minutes (time) from the keyboard
distanceMe = speedMe * time
distanceJill = speedJill * time
Display distanceMe
Display distanceJill
Stop
C++
#include <iostream>
using namespace std;
int main() {
//Declare variable speedMe
float speedMe;
//Declare variable speedJill
float speedJill;
//Declare variable time
float time;
//Declare variable distanceMe
float distanceMe;
//Declare variable distanceJill
float distanceJill;
//Get the speed your boat travels in (feet per minute) (speedMe) from the keyboard
printf("Enter the speed your boat travels in (feet per minute): ");
scanf("%f",&speedMe);
//Get the speed Jill's boat travels in (feet per minute) (speedJill) from the keyboard
printf("Enter the speed Jill's boat travels in (feet per minute): ");
scanf("%f",&speedJill);
//Get the number of minutes (time) from the keyboard
printf("Enter the the number of minutes: ");
scanf("%f",&time);
//distanceMe = speedMe * time
distanceMe = speedMe * time;
//distanceJill = speedJill * time
distanceJill = speedJill * time;
//Display distanceMe
cout<<"\nYour distance: "<<distanceMe<<"\n";
//Displayf distanceJill
cout<<"Jill's distance: "<<distanceJill<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment