Hello just looking for a little bit of help to finish my code. I have it up and running the only problem is my for looping. I've tried many ways to figure it out but none works not to mention am stuck on an infinite loop. I need the program output to look like this so far everthing works except for the
"At 1.44 seconds: 91.77 meters high" part my loop never goes on to the next step. Any help would be appreciated.The code is below
// OUTPUT
7. Lets see how far a projectile can be launched!
8.
9 You are on the surface of Earth at a gravity of 9.81 meters per second squared.
10.
11. Please enter the initial angle of your projectile (0.0 to 90.0): 45
12. Please enter the initial velocity your projectile (0.0 to 999.99):100
13. Please enter the number of height measurements to display (0 to 99):10
14.
15. At 1.44 seconds: 91.77 meters high
16. At 2.88 seconds: 163.15 meters high
17. At 4.33 seconds: 214.14 meters high
18. At 5.77 seconds: 244.73 meters high
19. At 7.21 seconds: 254.93 meters high
20. At 8.65 seconds: 244.73 meters high
21. At 10.09 seconds: 214.14 meters high
22. At 11.54 seconds: 163.15 meters high
23. At 12.98 seconds: 91.77 meters high
24. At 14.42 seconds: 0.00 meters high
25.
26. Total Time: 14.42
27. Total Distance: 1019.72
28. Height at Apogee: 254.93
#include<iostream>
#include<cmath>
#include<iomanip>
#include<math.h>
#include<stdio.h>
using namespace std;
cout<<"Lets see how far a projectile can be launched!"<< endl;
cout<< endl;
cout<<"You are on the surface of Earth at a gravity of 9.81 meters per secound squared."<<endl;
cout<<endl;
cout<<"Please enter the initial angle of your projectile (0.0 to 90.0):";
for (cin >> Angle; Angle <= 0.0 || Angle >= 90.0; cin >> Angle)
{
cout<<"Please enter the initial angle of your projectile (0.0 to 90.0):";
}
cout<<"Please enter the initial velocity your projectile (0.0 to 999.99):";
for (cin >> Velocity; Velocity <= 0.0 || Velocity >= 999.99; cin >> Velocity)
{
cout<<"Please enter the initial angle of your projectile (0.0 to 999.99):";
}
cout<<"Please enter the number of height measurments to display (0 to 99):";
for (cin >> increments; increments <= 0 || increments >= 99; cin >> increments)
{
cout<<"Please enter the number of height measurments to display (0 to 99):";
}
for (cin >> Angle; Angle <= 0.0 || Angle >= 90.0; cin >> Angle)
{
cout<<"Please enter the initial angle of your projectile (0.0 to 90.0):";
}
cout<<"Please enter the initial velocity your projectile (0.0 to 999.99):";
for (cin >> Velocity; Velocity <= 0.0 || Velocity >= 999.99; cin >> Velocity)
{
cout<<"Please enter the initial angle of your projectile (0.0 to 999.99):";
}
cout<<"Please enter the number of height measurments to display (0 to 99):";
for (cin >> increments; increments <= 0 || increments >= 99; cin >> increments)
{
cout<<"Please enter the number of height measurments to display (0 to 99):";
}
Thanks for the advice as for all the looping in the beginning I found it easier that why. It just worked for me. Am new to programing so sometimes I program a longer more time consuming way useing another method to get some practice time.
this creates an intial set of values but is never updated.
if the for loop needs to represent units of time then you could do something like....
1 2 3 4 5 6
for (int i = 0; i < increments; i++)
{
use i as the time variable in your calculations in here;
calculate needed data;
output data;
}
if the time is in second then when i = 0 is time 0, i = 1 is one second, and so on.
if you need different deltas then you can change the way i increments.
1 2 3 4 5 6
for (double i = 0; i < increments; i += (totTime/increments)) // or whatever value you need to increment by.
{
use i as the time variable in your calculations in here;
calculate needed data;
output data;
}