I have gotten this to work nicely, but when speed hits a certain speed it want it to stay that speed and not increase. The code does this to an extent, but when I am printing out the values one the the values hit 270 and then drops back down to 250. I do not want it so surpass 250 ever. Also the decent variable keeps moving up should it not stay the same value when max speed is hit or is this right and it is behaving right it just looks wrong to me? What I am getting at is should the distance traveled be more if the object has hit terminal velocity which i set to 250 every second ? Or do I have to set up the code differntly? Like have an if statement in there to say if mySpeed = maxSpeed then only use a certian decent rate? Well this is straight out of a physics book so…
Thanks for any help
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JumpSimR
{
class Program
{
static void Main(string[] args)
{
//non modifiable constants
const double maxSpeed = 250; //terminal velocity
const double g = 32.17; //imeriial unity feet per sec g = dv/dt
//variablbes used for player
double mySpeed; //current spped of person
double myAlt; //altitude of the person
double myDist; //distance travled for jump
double t; //time in simulation
//parachute variables
bool deploy;
bool lCord;
bool rCord;
double alt;
//get the alttitude from user input
Console.WriteLine("Enter Jump Altitued:");
Console.WriteLine("a for 30000 Ft");
Console.WriteLine("b for 25000 Ft");
Console.WriteLine("c for 15000 Ft");
String alt1 = Console.ReadLine();
if (alt1.Equals("a"))
{
alt = 30000;
}
else if (alt1.Equals("b"))
{
alt = 25000;
}
else { alt = 15000; }
Console.WriteLine("The Hight of the jump is " + alt);
myAlt = alt; //assign player alt to jump hight
t = 1;
mySpeed = 0;
deploy = false;
while(myAlt > 0)
{
if (maxSpeed > mySpeed){
mySpeed = g * t;
}
else if (mySpeed >= maxSpeed)
{
mySpeed = maxSpeed;
}
myDist = mySpeed * t; //distace = velocity * time
if (0 > myAlt - myDist) { myAlt = 0; } else { myAlt -= myDist; } //subtract distance travled from starting alt
Console.WriteLine("My Speed: " + mySpeed);
Console.WriteLine("My Distance: " + myDist);
Console.WriteLine("Altitude: " + myAlt);
t++;
}
// keep screen from going away
// when run from VS.NET
Console.ReadLine();
}
}
}
Take out the else, you were allowing it to pass the max for that one iteration: