#include <iostream> using namespace std; int main() { int iPlayerAngle; // ask the player for an initial angle float fPlayerSpeed; //ask the player for an initial speed float fDistanceFormula; // X value for calculating the distance traveled cout << "Choose an initial angle of 15, 30, 45, 60, or 75: "; do { cin >> iPlayerAngle; if( iPlayerAngle > 0, iPlayerAngle < 90, (iPlayerAngle % 15) == 0 ) cout << "That's a valid angle!\n"; else cout << "Try again!\n"; } while( iPlayerAngle < 0, iPlayerAngle > 90, (iPlayerAngle % 15) != 0 ); cout << "Now choose an initial speed from 1 - 10: "; do { cin >> fPlayerSpeed; if( fPlayerSpeed > 1.0, fPlayerSpeed < 10.0 ) cout << "Great!\n"; else cout << "Try again.\n"; } while( fPlayerSpeed < 1.0, fPlayerSpeed > 10.0 ); switch( iPlayerAngle ) { case '15': fDistanceFormula == 0.5; break; case '30': fDistanceFormula == 0.866; break; case '45': fDistanceFormula == 1.0; break; case '60': fDistanceFormula == 0.866; break; case '75': fDistanceFormula == 0.5; break; } float fProjectile = fPlayerSpeed * fPlayerSpeed * fDistanceFormula / 10; cout << "Your projectile flew a total distance of: " << fProjectile << "\n"; std::cin.get(); std::cin.get(); return 0; } |
#include <iostream> using namespace std; int main() { int iPlayerAngle; // ask the player for an initial angle float fPlayerSpeed; //ask the player for an initial speed float fDistanceFormula = 0; // X value for calculating the distance traveled float fProjectile = 0; cout << "Choose an initial angle of 15, 30, 45, 60, or 75: "; do { cin >> iPlayerAngle; if( iPlayerAngle > 0, iPlayerAngle < 90, (iPlayerAngle % 15) == 0 ) cout << "That's a valid angle!\n"; else cout << "Try again!\n"; } while( iPlayerAngle < 0, iPlayerAngle > 90, (iPlayerAngle % 15) != 0 ); cout << "Now choose an initial speed from 1 - 10: "; do { cin >> fPlayerSpeed; if( fPlayerSpeed > 1.0, fPlayerSpeed < 10.0 ) cout << "Great!\n"; else cout << "Try again.\n"; } while( fPlayerSpeed < 1.0, fPlayerSpeed > 10.0 ); switch( iPlayerAngle ) { case '15': fDistanceFormula = 0.5; break; case '30': fDistanceFormula = 0.866; break; case '45': fDistanceFormula = 1.0; break; case '60': fDistanceFormula = 0.866; break; case '75': fDistanceFormula = 0.5; break; } fProjectile = fPlayerSpeed * fPlayerSpeed * fDistanceFormula / 10; cout << "Your projectile flew a total distance of: " << fProjectile << "\n"; std::cin.get(); std::cin.get(); return 0; } |
#include <iostream> using namespace std; int main() { int iPlayerAngle; // ask the player for an initial angle float fPlayerSpeed, fProjectile; //ask the player for an initial speed float fDistanceFormula = 0; // X value for calculating the distance traveled int iTries = 0; // tries the player has made int iLucky; // varying the Target int numbers_added_together; float fRand_number; cout << "Enter your lucky number: \n"; cin >> iLucky; for (int i=1; i<iLucky; i++) { numbers_added_together = iLucky + i; } while (numbers_added_together > 10) { fRand_number = (numbers_added_together - 9); break; } do //Game Loop Beginning { cout << "\n\nThe target is a distance of " << fRand_number << " away.\n"; cout << "\n\nTry to get a distance between " << ( fRand_number - 0.5 ); cout << " and " << (fRand_number + 0.5); /******* Get Angle *********/ cout << "\n\nChoose an angle of 15, 30, 45, 60, or 75: "; do { cin >> iPlayerAngle; if( iPlayerAngle > 0, iPlayerAngle < 90, (iPlayerAngle % 15) == 0 ) cout << "That's a valid angle!\n"; else cout << "That's not a valid angle. It must be one of the five given values.\n"; } while( iPlayerAngle < 0, iPlayerAngle > 90, (iPlayerAngle % 15) != 0 ); /******** Get Speed **********/ cout << "Now choose an initial speed from 1 - 10: "; do { cin >> fPlayerSpeed; if( fPlayerSpeed >= 1.0, fPlayerSpeed <= 10.0 ) cout << "Great!\n"; else cout << "That is not a valid speed. It must be between 1.0 and 10.0.\n"; } while( fPlayerSpeed < 1.0, fPlayerSpeed > 10.0 ); /******** get X value for Distance Formula *********/ switch( iPlayerAngle ) { case 15: fDistanceFormula = 0.5; break; case 30: fDistanceFormula = 0.866; break; case 45: fDistanceFormula = 1.0; break; case 60: fDistanceFormula = 0.866; break; case 75: fDistanceFormula = 0.5; break; } /******* Calculate the distance the projectile flew ***********/ fProjectile = fPlayerSpeed * fPlayerSpeed * fDistanceFormula / 10; cout << "Your projectile flew a total distance of: " << fProjectile << "\n\n\n"; ++iTries; } while( (fProjectile < (fRand_number - 0.5)) || (fProjectile > (fRand_number + 0.5)) ); // Game Loop End iTries == 1 ? cout << "It only took you 1 try!" : cout << "It took you " << iTries << " tries!\n\n"; std::cin.sync(); std::cin.get(); return 0; } |