-
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;
for(i=1;i<7;i++)
{
seat[i]="unreserved";
}
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;
i=0;
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;
}
for(i=1;i<7;i++)
{
cout<<seat[i]<<" ";
}
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);
}
-
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
-
Replies: 11
Last Post: 07-16-2007, 09:36 PM
-
By athomas42 in forum .NET
Replies: 1
Last Post: 06-25-2007, 04:54 PM
-
By ObiWan in forum VB Classic
Replies: 3
Last Post: 05-23-2006, 10:35 AM
-
By Fred Mayes in forum Java
Replies: 1
Last Post: 06-05-2001, 06:12 AM
-
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
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|