View Single Post
Old 11-28-2006, 01:47 AM   #1 (permalink)
joelw
Code Monkey
 
Join Date: Sep 2006
Posts: 36
joelw is on a distinguished road
Help with storing data in structure

ok, i need help writing a program that stores data about a basketball player in a structue. I need to create a structure for players name, players number, and by points the player scored. I need to keep an array of 5 of these structures. Which each element is for a different player on a team. The program should ask the user to enter data for each player. It should then show a table of each players number, name, and points scored and finally it should calculate and display the total points earned by the team.

so far i have written this but some how i think im doing it wrong if anyone could help thanks in advance.

Code:
#include <iostream>
#include <iomanip>

using namespace std;

const int SIZE = 25;

struct Players
{
       char name[SIZE];        //Player's Name
       int playNum;            //Player's Number
       double Points;          //Point's Scored
};    

int main()
{
    const int NUM_PLAYERS = 5; //Number of Players
    Players players[NUM_PLAYERS];      //Array of sturctures
    int index;                 //Loop
    
    // Get Player data.
    cout << "Enter the players by ";
    cout << " players, numbers, and their scores.\n";
    for (index = 0; index < NUM_PLAYERS; index++)
    {
        cout << "Please enter players name: ";
        cin.ignore(); 
        cin.getline(players.name[SIZE];
joelw is offline   Reply With Quote