DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: making a string array

  1. #1
    Join Date
    Apr 2010

    making a string array

    I am having troubles making an input of a string and bringing it into a string array then outputting it to the screen. here's the code, to get to the problem hit 1, enter, 1, enter, 2, enter, type your first name, enter, type your last name, enter and then it shows hex instead of an actual name.

    #include <iostream>
    #include <string>
    #include <fstream>
    #include <cmath>

    using namespace std;
    int reserveseat(int seat);
    int unreserveseat(string first_name, string last_name, int seatnum, string seat[]);

    int main()
    const int seatnum = 7;
    string seat[seatnum];
    string name[seatnum];
    string lname[seatnum];
    int i;
    int choice;
    int seatres=1;
    int want;
    char first_name;
    char last_name;


    cout << "Welcome to Airplane Fantasia"<<endl;
    cout << "Would you like to: "<<endl;
    cout << "1. Reserve a seat"<<endl;
    cout << "2. Unreserve a seat"<<endl;
    cout << "3. Exit the program"<<endl;
    cout << "choose one, type the cooresponding number and press enter."<<endl;
    cin >>choice;


    if(choice = 1)

    while(seatres == 1)
    cout << "what seat number would you like? enter a number 1-6 and press enter"<<endl;
    cin >> want;
    if (seat[want]=="unreserved")
    seatres = reserveseat(want);
    seat[want] = 1;
    cout << "what is your name? type first name press enter then last name and press enter"<<endl;
    cin >>name[want];
    cin >>lname[want];

    cout << name<<" "<<lname;
    else if(seat[want]=="reserved")

    cout << "That seat is already taken, please choose another"<<endl;
    cout<<seat[i]<<" ";


    system ("pause");
    return 0;
    int reserveseat(int seat)
    int contin;
    cout << "you choose to reserve seat number "<<seat<<endl;
    cout << "would you like to reserve another seat? type 1 for yes and 2 for no and press enter"<<endl;
    cin >> contin;
    return (contin);

  2. #2
    Join Date
    Dec 2003
    cout << name<<" "<<lname;

    this is the problem, them are arrays so you need
    name[desired_location] etc, to get into the array.

    Because you do not have this, it prints the address of the array's location, which is a pointer, and by default prints in hex.

Similar Threads

  1. string array in c++
    By emeric in forum C++
    Replies: 11
    Last Post: 07-16-2007, 09:36 PM
  2. Submitting Infopath to a .net Web Service
    By athomas42 in forum .NET
    Replies: 1
    Last Post: 06-25-2007, 04:54 PM
  3. SQL DMO Restores in VB?
    By ObiWan in forum VB Classic
    Replies: 3
    Last Post: 05-23-2006, 10:35 AM
  4. Replies: 1
    Last Post: 06-05-2001, 06:12 AM
  5. VB/C Array parameters
    By Gastao Woelfert in forum VB Classic
    Replies: 0
    Last Post: 09-01-2000, 08:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center