My lab professor wants us to use a while statement to have a parabola curving downward (gravity equation), but not going negative without an if statement in c++11. The code below works fine except for the fact that one negative value is still used. Is there a way to remove this last x/y value?
include
include
using namespace std;
int main() { const double gravAccel = 9.82; double initHeight; double itemAngle; double itemSpeed; double horzCoord = 0; double vertCoord; cout <<"What is the initial height of the projectile?"; cin >> initHeight; cout <<"What angle is the projectile launched at?"; cin >> itemAngle; cout <<"What is the projectile's speed?"; cin >> itemSpeed; while (vertCoord >= 0) { vertCoord = initHeight + horzCoordtan(itemAngle) - ((gravAccelpow(horzCoord,2))/(2*(pow(itemSpeed*cos(itemAngle),2)))); cout << horzCoord << "meters, " << vertCoord << "meters" << endl; horzCoord++; }return 0; }
Aucun commentaire:
Enregistrer un commentaire