// artillery.cpp, Maggie Johnson // Description: A simple game with a little physics #include #include #include using namespace std; const int kNumShells = 10; // allowed 10 shells per target const int kMinDist = 200; // min distance for a target const int kMaxDist = 900; // max distance for a target const double kVelocity = 200.0; // initial velocity of 200 ft/sec const double kGravity = 32.2; // gravity for distance calculation const double kPi = 3.1415; // Returns the distance a shot travels given its angle. int DistanceCalc (double in_angle) { double time_in_air; // The following calculates how far the shot goes given // its angle of projection, velocity, and how long it stays // in the air. time_in_air = (2.0 * kVelocity * sin(in_angle)) / kGravity; return (int) round((kVelocity * cos(in_angle)) * time_in_air); } // Get user's angle input and calculates distance where shot lands. // Returns the distance the shot lands. int CheckShot() { int distance; double angle; cout << "What angle? " << endl; if (!(cin >> angle)) return -1; // Convert to radians. angle = (angle * kPi) / 180.0; distance = DistanceCalc(angle); return distance; } // Generate a random number for the enemy position. int Initialize() { int enemy_position; // Initialize random seed. srand (time(NULL)); // Generate random number between kMinDist and kMaxDist enemy_position = rand() % kMaxDist + kMinDist; cout << "The enemy is " << enemy_position << " feet away!!!" << endl; return enemy_position; } // This function plays the game int Fire(int number_killed) { int enemy, shots, hit; int distance; // Initialize variables. shots = kNumShells; enemy = Initialize(); distance = 0; hit = 0; do { // Get the distance where shot lands & compare it to enemy position. distance = CheckShot(); // Some error checking on the input. if (distance == -1) { cout << "Enter numbers only..." << endl; cin.clear(); cin.ignore(10000,'\n'); continue; } // Compare the enemy position with the computed distance. if (abs(enemy - distance) <= 1) { hit = 1; number_killed++; cout << "You hit him!!!" << endl; cout << "It took you " << kNumShells - shots + 1 << " shots." << endl; cout << "You have killed " << number_killed << " enemies." << endl; } else { shots--; if (distance > enemy) { cout << "You over shot by " << abs(enemy - distance) << endl; } else { cout << "You under shot by " << abs(enemy - distance) << endl; } } } while ((shots > 0) && (!(hit))); if (shots == 0) cout << "You have run out of ammo..." << endl; return number_killed; } // This shows the introductory screen. void StartUp() { cout << "Welcome to Artillery." <> done; } while (done != 'n'); cout << "You killed " << killed << " of the enemy." << endl; }
Standard input is empty
prog.cpp:3:10: error: #include expects "FILENAME" or <FILENAME>
prog.cpp:4:10: error: #include expects "FILENAME" or <FILENAME>
prog.cpp:5:10: error: #include expects "FILENAME" or <FILENAME>
prog.cpp: In function 'int DistanceCalc(double)':
prog.cpp:22:48: error: 'sin' was not declared in this scope
time_in_air = (2.0 * kVelocity * sin(in_angle)) / kGravity;
^
prog.cpp:23:47: error: 'cos' was not declared in this scope
return (int) round((kVelocity * cos(in_angle)) * time_in_air);
^
prog.cpp:23:63: error: 'round' was not declared in this scope
return (int) round((kVelocity * cos(in_angle)) * time_in_air);
^
prog.cpp: In function 'int CheckShot()':
prog.cpp:32:3: error: 'cout' was not declared in this scope
cout << "What angle? " << endl;
^
prog.cpp:32:29: error: 'endl' was not declared in this scope
cout << "What angle? " << endl;
^
prog.cpp:33:9: error: 'cin' was not declared in this scope
if (!(cin >> angle))
^
prog.cpp: In function 'int Initialize()':
prog.cpp:47:15: error: 'NULL' was not declared in this scope
srand (time(NULL));
^
prog.cpp:47:19: error: 'time' was not declared in this scope
srand (time(NULL));
^
prog.cpp:47:20: error: 'srand' was not declared in this scope
srand (time(NULL));
^
prog.cpp:50:25: error: 'rand' was not declared in this scope
enemy_position = rand() % kMaxDist + kMinDist;
^
prog.cpp:51:3: error: 'cout' was not declared in this scope
cout << "The enemy is " << enemy_position << " feet away!!!" << endl;
^
prog.cpp:51:67: error: 'endl' was not declared in this scope
cout << "The enemy is " << enemy_position << " feet away!!!" << endl;
^
prog.cpp: In function 'int Fire(int)':
prog.cpp:72:7: error: 'cout' was not declared in this scope
cout << "Enter numbers only..." << endl;
^
prog.cpp:72:42: error: 'endl' was not declared in this scope
cout << "Enter numbers only..." << endl;
^
prog.cpp:73:7: error: 'cin' was not declared in this scope
cin.clear();
^
prog.cpp:78:29: error: 'abs' was not declared in this scope
if (abs(enemy - distance) <= 1) {
^
prog.cpp:81:7: error: 'cout' was not declared in this scope
cout << "You hit him!!!" << endl;
^
prog.cpp:81:35: error: 'endl' was not declared in this scope
cout << "You hit him!!!" << endl;
^
prog.cpp:87:9: error: 'cout' was not declared in this scope
cout << "You over shot by " << abs(enemy - distance) << endl;
^
prog.cpp:87:65: error: 'endl' was not declared in this scope
cout << "You over shot by " << abs(enemy - distance) << endl;
^
prog.cpp:89:9: error: 'cout' was not declared in this scope
cout << "You under shot by " << abs(enemy - distance) << endl;
^
prog.cpp:89:66: error: 'endl' was not declared in this scope
cout << "You under shot by " << abs(enemy - distance) << endl;
^
prog.cpp:94:5: error: 'cout' was not declared in this scope
cout << "You have run out of ammo..." << endl;
^
prog.cpp:94:46: error: 'endl' was not declared in this scope
cout << "You have run out of ammo..." << endl;
^
prog.cpp: In function 'void StartUp()':
prog.cpp:100:3: error: 'cout' was not declared in this scope
cout << "Welcome to Artillery." <> done;
^
prog.cpp:100:37: error: expected primary-expression before '>' token
cout << "Welcome to Artillery." <> done;
^
prog.cpp:100:39: error: 'done' was not declared in this scope
cout << "Welcome to Artillery." <> done;
^
prog.cpp: At global scope:
prog.cpp:101:5: error: expected unqualified-id before 'while'
} while (done != 'n');
^
prog.cpp:102:3: error: 'cout' does not name a type
cout << "You killed " << killed << " of the enemy." << endl;
^
prog.cpp:103:1: error: expected declaration before '}' token
}
^
Standard output is empty