MiniProjects in C++
- You have 10 bullets to hit 15 opponent soldiers standing as a unit in rows and columns. Use minimum bullets to hit maximum soldiers.
#include <iostream>
using namespace std;
int main() {
//define location of opponent Soldiers
int opponent[3][5] = { {0,0,1,0,0},{0,1,0,1,0},{1,0,0,0,1}};
//number of bullets
int bullets = 10;
int killed=0;
int row, column, usedbullet = 0;
while (usedbullet <= 10){
cout << "Enter row number 0 to 2 : "<<endl;
cin >> row;
cout << "Enter column number 0 to 4 : " << endl;
cin >> column;
usedbullet++;
if (opponent[row][column] == 1) {
cout << " Wow! You hit the target !! "<< endl;
killed++;
opponent[row][column] = 0;
}
else
cout << "You missed the target !! Continue firing " << endl;
}
cout << "You killed "<< killed << " number of opponentsoldiers" <<endl;
}
2. You have 10 bullets to hit 15 opponent soldiers standing as a unit in rows and columns. Use minimum bullets to hit maximum soldiers. Print number of opponents you killed and also the number of bullets. You may also ask user to place the opponent army.