The goal here is to write a code that will calculate whether or not a water balloon can be dropped on someone depending on how far away they are, how fast they are walking, and comparing how long it will take them to reach the hit box vs how long for the balloon to drop.
An example output is meant to look like this:
How far away is your friend(feet)? 200
How fast are they walking(feet/sec)? 3
How high are you before dropping your ballon(feet)? 100
It will take 66.66 seconds for them to reach the balloon point
It will take 4.57 seconds for your balloon to travel to the ground
If you wait 62.09 seconds, you will hit them
This is all I have so far. I know it's not much, but I'm going to continue working on it and I'd just like some tips for how best to proceed so I don't waste time. Thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <cmath>
usingnamespace std;
int main(){
int velocity = 0;
int distance = 0;
int verDist;
int speed;
int horDist;
int time1;
cout <<"How far away is your friend(feet)?: ";
cin >> verDist;
cout <<"How fast is your friend walking(feet/sec)?: ";
cin >> speed;
cout <<"How high are you dropping the balloon from(feet)?: ";
cin >> horDist;
}
Well, my first suggestion would be to work out the necessary physics equations. It's simple mechanics stuff, so that shouldn't be too difficult. Once that's done you simply put the equations into code to get the result.
You might need to #include <cmath> though for things such as the square root, for deriving things such as time.
I've been working on this code for a little while now and this is what I have. The current problem is it's not displaying my output statements at the end? So I don't know if the math is even right.
#include <iostream>
#include <cmath>
#include <stdio.h>
usingnamespace std;
int main(){
float velocity = 0;
float timeElapsed = 0;
float distance;
float height;
float walkSpeed;
cout <<"How far away is your friend(feet)?: ";
cin >> distance;
cout <<"How fast is your friend walking(feet/sec)?: ";
cin >> walkSpeed;
cout <<"How high are you dropping the balloon from(feet)?: ";
cin >> height;
while(height > 0){
timeElapsed += 0.001;
height -= velocity/1000;
velocity += 0.032 - velocity * 0.0012;
}
return timeElapsed;
float timeToWalk = distance / walkSpeed;
float waitTime = timeToWalk - timeElapsed;
if(waitTime > 0.0){
printf ("It will take %f.2 seconds for them to reach the balloon point.", timeToWalk);
printf ("It will take %f.2 seconds for your balloon to travel to the ground.", timeElapsed);
printf ("If you wait %f.2 seconds, you will hit them.", waitTime);
}else
printf ("It will take %f.2 seconds for them to reach the balloon point.", timeToWalk);
printf ("It will take %f.2 seconds for your balloon to travel to the ground.", timeElapsed);
printf ("If you wait %f.2 seconds, you will hit them.", waitTime);
cout << "It is too late to drop your balloon";
}
#include <iostream>
#include <cmath>
#include <stdio.h>
usingnamespace std;
int main(){
float velocity = 0;
float timeElapsed = 0;
float distance;
float height;
float walkSpeed;
cout <<"How far away is your friend(feet)?: ";
cin >> distance;
cout <<"How fast is your friend walking(feet/sec)?: ";
cin >> walkSpeed;
cout <<"How high are you dropping the balloon from(feet)?: ";
cin >> height;
while(height > 0){
timeElapsed += 0.001;
height -= velocity/1000.0;
velocity += 0.032 - velocity * 0.0012;
}
float timeToWalk = distance / walkSpeed;
float waitTime = timeToWalk - timeElapsed;
if(waitTime > 0.0){
printf ("\nIt will take %.2f seconds for them to reach the balloon point.", timeToWalk);
printf ("\nIt will take %.2f seconds for your balloon to travel to the ground.", timeElapsed);
printf ("\nIf you wait %.2f seconds, you will hit them.\n", waitTime);
}else{
printf ("\nIt will take %.2f seconds for them to reach the balloon point.", timeToWalk);
printf ("\nIt will take %.2f seconds for your balloon to travel to the ground.", timeElapsed);
cout << "\nIt is too late to drop your balloon.\n";
}
}