473,385 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can I make this program work? Problem with arrays

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5. void details( string fNum,int dHour,int dMin,int aHour,int aMin, string aircraft);
  6.  
  7. int main()
  8. {
  9.  //Flights tB:Trinidad-Barbados,tN:Trinidad to New York,tL:Trinidad to London.
  10.         int dHour;
  11.         int dMin;
  12.         string fNum;
  13.         int aHour;
  14.         int aMin;
  15.         int durHour;
  16.         int durMin;
  17.         string aircraft;
  18.         int dOption;
  19.         bool availabe=true;
  20.         int seats[max_seat_rows][max_seat_cols]={0};
  21.         int resAmt;
  22.         int empty=0;
  23.  
  24. //Recording Reservations for Passengers
  25.         cout<<"\nWhat is your destination?\n"<<endl<<"1) Trinidad to Barbados"<<endl
  26.                                                <<"2) Trinidad to New York"<<endl
  27.                                                <<"3) Trinidad to London\n"<<endl;
  28.         cout<<"Please enter either 1,2 or 3."<<endl;
  29.         cin>>dOption;
  30.  
  31.         switch (dOption)
  32.         {
  33.                 case 1:
  34.                         dHour=7;
  35.                         dMin=0;
  36.                         fNum="USC 215";
  37.                         aHour=7;
  38.                         aMin=45;
  39.                         durHour=0;
  40.                         durMin=45;
  41.                         aircraft="MD 82";
  42.                         max_seat_rows=15;
  43.                         max_seat_cols=4;
  44.  
  45.  
  46.                 break;
  47.  
  48.                 case 2:
  49.                         dHour=6;
  50.                         dMin=0;
  51.                         fNum="USC 400";
  52.                         aHour=3;
  53.                         aMin=0;
  54.                         durHour=6;
  55.                         durMin=0;
  56.                         aircraft="Boeing 737";
  57.                         max_seat_rows=32;
  58.                         max_seat_cols=6;
  59.                 break;
  60.  
  61.                 case 3:
  62.                         dHour=7;
  63.                         dMin=30;
  64.                         fNum="USC 900";
  65.                         aHour=9;
  66.                         aMin=30;
  67.                         durHour=9;
  68.                         durMin=0;
  69.                         aircraft="Boeing 777";
  70.                         max_seat_rows=30;
  71.                         max_seat_cols=10;
  72.                 break;
  73.         }
  74.  
  75.  
  76.                 details(fNum,dHour,dMin,aHour,aMin, aircraft);
  77. //This section declares everything in all of the arrays to 0;
  78.  
  79.  
  80.                  for(int a=0;a<max_seat_rows;a++)
  81.                  {
  82.                         for(int b=0;b<max_seat_cols;b++)
  83.                         {
  84.                                 cout<<seats[a][b]<<"\t";
  85.  
  86.                         }
  87.                         cout<<endl;
  88.  
  89.                  }
  90.  
  91. // This section determines how many empty seats there are
  92.  
  93.                  for(int c=0;c<max_seat_rows;c++)
  94.                  {
  95.                         for(int d=0;d<max_seat_cols;d++)
  96.                         {
  97.                                 if (seats[c][d]==0)
  98.                                 empty++;
  99.  
  100.                         }
  101.                  }
  102.  
  103.                         cout<<"There are "<<empty<<" empty seats"<<endl;
  104. //This section takes the amount of seats that the user wishes to reserve and makes them unavailable
  105.  
  106.  
  107.                         cout<<"How many seats would you like to reserve?"<<endl;
  108.                         cin>>resAmt;
  109.  
  110.                         for (int e=0;e>resAmt;e++)
  111.                         {
  112.  
  113.                                         for(int c=0;c<max_seat_rows;c++)
  114.                                         {
  115.                                                 for(int d=0;d<max_seat_cols;d++)
  116.                                                 {
  117.                                                         if (seats[c][d]==0)
  118.                                                         {
  119.                                                         seats[c][d]=1;
  120.                                                         }
  121.                                                         else
  122.                                                         {
  123.                                                         cout<<"This seat is already taken"<<endl;
  124.                                                         }
  125.  
  126.                                                 }
  127.                                         }
  128.  
  129.  
  130.                         }
  131.  
  132. return 0;
  133.  
  134.  
  135. }
  136.  
  137.  
  138.                void details( string fNum,int dHour,int dMin,int aHour,int aMin, string aircraft)
  139. {
  140.                 cout<<"\n\nYou Have Chosen to Fly on Flight Number "<<fNum<<endl;
  141.                 cout<<"The Flight will Depart at "<<dHour<<":"<<dMin<<endl;
  142.                 cout<<"The Flight will Arrive at its Destination in "<<aHour<<" Hours and "<<aMin<<" Minutes"<<endl;
  143.                 cout<<"Aircraft is the "<<aircraft<<endl;
  144.  
  145. }
  146.  
Dec 22 '09 #1
2 1456
gpraghuram
1,275 Expert 1GB
In this declaration
int seats[max_seat_rows][max_seat_cols]={0};

what is value of max_seat_rows and max_seat_cols

If you want to set the size dynamically then decalre a double pointer array and initialize it.

Raghu
Dec 22 '09 #2
weaknessforcats
9,208 Expert Mod 8TB
Read this

http://bytes.com/topic/c/insights/77...rrays-revealed

before you start working with arrays.
Dec 22 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Ricky | last post by:
thanks for the replysir. i have made this code so far in declaring the NFA. In fact i do know what am i supposed to do , i just cant get it right. please have a look at the following code and tell...
12
by: bartek | last post by:
template <class T, unsigned size> struct Array { typedef unsigned SizeType; typedef T ValueType; typedef T* Ptr; typedef T const* ConstPtr; // Default copy ctor and assignment op...
1
by: carl bloc | last post by:
Have this much done but need help with this bit of code: allow user to modify existing draw data. I think I need a counter to give week numbers so the user can select a week number rather than a...
60
by: Dominique Léger | last post by:
Hello guys, I'm kinda new to C, and I'm having a hard time with strings. What I'm trying to do is a simple function that trims spaces & tabs at the beginning of a given string. For example, I...
7
by: Robert Bachmann | last post by:
Two years I wrote a simple cesar encryption program, it worked but it relied on ASCII. So today I tried to make an portable cesar encryption. Please tell me if the code below is really protable. ...
8
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
2
by: Zerofury | last post by:
Okay this is what i'm attempting to do. I have to modify this program that i wrote so that it allows the user to list items by alpha as an option on the main menu. Here is my problem. If i sort the...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.