Start New Discussion within our Software Development Community

I am working on a struct. The two requirements are for the user to be able to input an entry and then view it. I have two questions, when entering the data shouldn't I be able to enter spaces when entering the address i.e. 654 smith st and store that as address1? and why am i getting a memory addres for my print function?
it displays

,
-654649840

#include <string>
#include <iostream>

using namespace std;

struct playerType
{
    string first;
    string last;
    string address1;
    string address2;
    string city;
    string state;
    string zip;
    int jersey;
}; //end struct

void readIn(playerType player)
{
    cin >> player.first >> player.last;
    cin    >> player.address1 >> player.address2;
    cin    >> player.city >> player.state;
    cin    >> player.zip >> player.jersey;
}

void printPlayer(playerType player)
{
    cout << endl << endl << player.first << " " << player.last 
        << endl << player.address1 << endl << player.address2
        << endl << player.city << ", " << player.state
        << " " << player.zip << endl << player.jersey << endl;
}


int main()
{
    playerType player;

    cout << "Enter all of the player's information in order shown\n"
        "pressing Enter after each entry. First name, last name,\n"
        "address line 1, address line 2, city, state, zip, and jersey number: ";

    readIn(player);
    printPlayer();

    
} //end main

1. To read your data with space use cin.getline( ... )
2. To use the player-data in you functions you need to pass it as reference or as a pointer for example:

void printPlayer(playerType &player) 
...
printPlayer(player);

or

void printPlayer(playerType *player) 
...
printPlayer(&player);
This question has already been answered. Start a new discussion instead.