Video Game Player Program

Write a program to do the following. In main declare a Player Name Array and a Score Array. Declare the size of the arrays to be 100. In the InputData function input the player name and score into the arrays for an unknown number of players up to 100.

If you have a problem coding, post your code, we'll help you debug syntax or logic errors.

using namespace std;

const double poundsPerKilogram = 2.2046;
const int ouncesPerPound = 16;
const int gramsPerKilogram = 1000;

void getInput(double& pounds, double& ounces);
// Precondition: User is ready to enter values correctly.
// Postcondition: The values of pounds and ounces have been set to the weight
// of the object.

double convertToGrams(double poundss, double ounces, double kilograms, double grams);
// Precondition: User is ready to enter values correctly.
// Postcondition: The values of kilograms and grams have been set to

void giveOutput(double kilograms, double grams);
// Precondition: The weight of the object is stored in kilograms and grams.
// Postcondition: The values of kilograms and grams have been written to the screen.

int main()
{
double pounds, ounces, kilograms, grams;
char ans;

do
{

getInput(pounds, ounces);
convertToGrams(kilograms, grams, pounds, ounces);
giveOutput(kilograms, grams);


cout << "Do you want to do another calculation?\n"
<< "Press y for yes, n for no,\n"
<< "and then press return: ";
cin >> ans;
cout << endl;

} while (ans == 'y' || ans == 'Y');

return 0;
}

void getInput(double& pounds, double& ounces)
{
cout << "Enter the weight of the object in pounds and ounces\n";
cout << "pounds: ";
cin >> pounds;
cout << "ounces: ";
cin >>ounces;

}

double convertToGrams(double pounds, double ounces, double kilograms, double grams)
{

kilograms = pounds / 2.2046;

kilograms = floor(kilograms); // extract just entire portion of kg
grams = (kilograms )*1000; // the substraction will be remaining grams
return kilograms;
return grams;
}

void giveOutput(double kilograms, double grams)
{

cout << "The object weighs " << kilograms << " kilograms and " << grams << " grams\n";

}

Sure! Here's an example of how you can write a program in C++ to accomplish this task:

```cpp
#include <iostream>
#include <string>

const int MAX_PLAYERS = 100;

void InputData(std::string playerNames[], int scores[], int& numPlayers) {
std::cout << "Enter player names and scores (or 'q' to quit)" << std::endl;
numPlayers = 0;

for (int i = 0; i < MAX_PLAYERS; i++) {
std::string playerName;
int score;

std::cout << "Enter player name: ";
std::getline(std::cin, playerName);

if (playerName == "q") {
break;
}

std::cout << "Enter score: ";
std::cin >> score;
std::cin.ignore(); // Ignore the newline character in the input buffer

// Store the player name and score in their respective arrays
playerNames[numPlayers] = playerName;
scores[numPlayers] = score;

numPlayers++;
}
}

int main() {
std::string playerNames[MAX_PLAYERS];
int scores[MAX_PLAYERS];
int numPlayers = 0;

InputData(playerNames, scores, numPlayers);

// Display the player names and scores
std::cout << "Player Data:" << std::endl;
for (int i = 0; i < numPlayers; i++) {
std::cout << "Player Name: " << playerNames[i] << " - Score: " << scores[i] << std::endl;
}

return 0;
}
```

In this program, we declare two arrays - `playerNames` to store the names of the players, and `scores` to store their scores. We also declare a constant variable `MAX_PLAYERS` to specify the maximum number of players allowed (in this case, 100).

The `InputData` function is responsible for taking input from the user. It prompts the user to enter the player name and score in a loop. The loop continues until either the user enters 'q' for the player name or the maximum number of players is reached. Within the loop, the entered player name and score are stored in the respective arrays.

In the `main` function, we initialize the arrays and a variable `numPlayers` to keep track of the number of players entered. Then we call the `InputData` function to input the player data.

Finally, we display the player names and scores by looping through the arrays using the `numPlayers` variable.

Note: This implementation assumes inputting names with spaces is allowed. If not, you can use `std::cin >> playerName;` instead of `std::getline(std::cin, playerName);` to read a single word as the player name.