#include<iostream>
using namespace std;

int intro();
double getData();
double averageHigh();
double averageLow();
double indexHighTemp();
double indexLowTemp();
double table();

double i,j,hsum=0,lsum=0,aveh,avel,high=0,low=0,ind;
int const row=2,col=12,num=12;
double temp[row][col];
char month[20][num]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};
char space[]="                             ";

int main()
{getData();
table();
averageHigh();
averageLow();
indexHighTemp();
indexLowTemp();
return 0;
}

int intro()
{
cout<<"||||| |||| ||||| ||||   |||| ||||   ||||  ||  |     | ||||  |||   |||| "<<endl;
cout<<"  |   |    | | | |  |   |  | |      |   | |    |   |  |    |   |  |  | "<<endl;
cout<<"  |   |||| | | | ||||   |  | ||||   |   |       | |   |||| |||||  |||  "<<endl;
cout<<"  |   |    | | | |      |  | |      |   |        |    |    |   |  |  | "<<endl;
cout<<"  |   |||| | | | |      |||| |      ||||         |    |||| |   |  |   |"<<endl;
return 0;
}

double getData()
{
for (i=0;i<col;i++)
{do
 {intro();
  cout<<endl<<"INPUT TEMPERATURES FOR THE FOLLOWING MONTHS."<<endl;
  cout<<"(Highest temperature must be greater that lowest temperature)"<<endl<<endl<<endl;
  cout<<(month[i])<<": ";
  for (j=0;j<row;j++)
   {if (j==0)
     cout<<endl<<endl<<"Highest Temperature of the Month: ";
    else
     cout<<endl<<"Lowest Temperature of the Month: ";
    cin>>(temp[j][i]);
   }}
 while ((temp[0][i])<(temp[1][i]));
 }
return 0;
}

double averageHigh()
{for (i=0;i<col;i++)
 {hsum=(hsum+(temp[0][i]));}
aveh=hsum/12;
cout<<endl<<"The Average High Temperature is: ";
cout<<aveh;
return 0;
}

double averageLow()
{for (i=0;i<col;i++)
 {lsum=(lsum+(temp[1][i]));}
avel=lsum/12;
cout<<endl<<"The Average Low Temperature is: ";
cout<<avel;
return 0;
}

double indexHighTemp()
{ind=0;
for (i=0;i<col;i++)
 {if (high<=(temp[0][i]))
   {high=(temp[0][i]);
    ind=i;
   }
 }
cout<<endl<<"The Highest Temperature of the Year is: ";
cout<<(temp[0][ind]);
return 0;
}

double indexLowTemp()
{ind=0;
for (i=0;i<col;i++)
 {if (low>=(temp[1][i]))
   {low=(temp[1][i]);
    ind=i;
   }
 }
cout<<endl<<"The Lowest Temperature of the Year is: ";
cout<<(temp[1][ind]);
return 0;
}

double table()
{
intro();
cout<<"               HIGHEST TEMPERATURE          LOWEST TEMPERATURE"<<endl<<endl;
cout<<" JANUARY          "<<temp[0][0]<<space<<temp[1][0]<<endl;
cout<<" FEBRUARY         "<<temp[0][1]<<space<<temp[1][1]<<endl;
cout<<" MARCH            "<<temp[0][2]<<space<<temp[1][2]<<endl;
cout<<" APRIL            "<<temp[0][3]<<space<<temp[1][3]<<endl;
cout<<" MAY              "<<temp[0][4]<<space<<temp[1][4]<<endl;
cout<<" JUNE             "<<temp[0][5]<<space<<temp[1][5]<<endl;
cout<<" JULY             "<<temp[0][6]<<space<<temp[1][6]<<endl;
cout<<" AUGUST           "<<temp[0][7]<<space<<temp[1][7]<<endl;
cout<<" SEPTEMBER        "<<temp[0][8]<<space<<temp[1][8]<<endl;
cout<<" OCTOBER          "<<temp[0][9]<<space<<temp[1][9]<<endl;
cout<<" NOVEMBER         "<<temp[0][10]<<space<<temp[1][10]<<endl;
cout<<" DECEMBER         "<<temp[0][11]<<space<<temp[1][11]<<endl;
return 0;
}

c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(45) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(51) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(53) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(53) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(60) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(69) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(79) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(80) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(85) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(92) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(93) : error C2108: subscript is not of integral type
c:\users\ethelbert karl\visual studio 2008\projects\coe050\coe050\arrays.cpp(98) : error C2108: subscript is not of integral type
Build log was saved at "file://c:\Users\Ethelbert Karl\Visual Studio 2008\Projects\COE050\COE050\Debug\BuildLog.htm"
COE050 - 12 error(s), 0 warning(s)


i dont know why this error occurs....

please tell me whats the problem with my code

1) line 12: subscripts into arrays must be integers, not doubles. You have one of two choices here: either make the variables i and j integers on line 12 or typecast them to integers every place in your program where they are used as subscripts. Its a lot easier and less error prone to just make them integers on line 12.

2) line 15. The array is declared incorrectly. Should be like this:

char *month[] ={"JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"};

3) line 85: cout<<(temp[0][ind]); This has a similar problem as that described for line 12 -- variable ind is a double.

#include<iostream.h>
#include<conio.h>

const int row=13,col=6,num=78;
int i,j,r,c,area;
int m[num],n[num];
int x,x1,x2,t=0,p;
char str[row][col];
char a='*',y,z;

int space();
int seatplan();
int asteris();
int tickettype();
int Area();
int economy();
int column();
int reserveconfi();
int reserve();
int again();
int reserved();
int taken();

int main()
{clrscr();
asteris();
again();
getch();
return 0;
}

int asteris()
{for (i=0;i<row;i++)
 {for (j=0;j<row;j++)
  {str[i][j]=a;}
 }
return 0;
}

int error()
{clrscr();
cout<<endl<<endl<<"----------------------------------Invalid Input---------------------------------"<<endl;
cout<<endl<<"                             --Press b to go back--"<<endl;
return 0;
}

int seatplan()
{clrscr();
cout<<endl;
cout<<"              Airline Reservation"<<endl<<endl;
cout<<"         A     B     C     D     E     F"<<endl;
for (i=0;i<row;i++)
 {if (i+1<10)
	{cout<<"ROW"<<i+1<<"     ";}
	else
	{cout<<"ROW"<<i+1<<"    ";}
 for (j=0;j<col;j++)
  {cout<<str[i][j]<<"     ";}
	{if (i+1==3)
	  {cout<<"LEGEND: ";}
	 else if (i+1==4)
	  {cout<<" * - Available";}
	 else if (i+1==5)
	  {cout<<" X - Not Available";}
	 cout<<endl;}
	 }
cout<<endl;
return 0;
}

int tickettype()
{seatplan();
r=0;
c=0;
cout<<"What Class Do You Want: "<<endl;
cout<<"  [a] First Class"<<endl;
cout<<"  [b] Economy Class"<<endl;
cin>>y;
switch (y)
{
case 'a': area=0; Area(); break;
case 'b': economy(); break;
default: error();
	 cin>>y;
	 switch (y)
	 {case 'b': tickettype(); break;}
	 break;}
return 0;
}

int Area()
{seatplan();
cout<<"What Row Do You Want"<<endl;
if (area==0)
  {cout<<"(First Class Passengers May Only Choose Row[1-2]):";
  cin>>r;
  if ((r<1)||(r>2))
	{Area();}}
else if (area==1)
  {cout<<"(Non-Smoking Area are on Row[3-7]):";
  cin>>r;
  if ((r<3)||(r>7))
	  {Area();}}
else if (area==2)
  {cout<<"(Smoking Area are on Row[8-13]):";
  cin>>r;
  if ((r<8)||(r>13))
	  {Area();}}
column();
return 0;
}

int economy()
{seatplan();
cout<<"What Area Do You Want: "<<endl;
cout<<"  [a] Non-Smoking Area"<<endl;
cout<<"  [b] Smoking Area"<<endl;
cin>>y;
switch (y)
{
case 'a': area=1; Area(); break;
case 'b': area=2; Area(); break;
default: error();
	 cin>>y;
	 switch (y)
	 {case 'b': economy(); break;}
	 break;}
return 0;
}


int column()
{seatplan();
 cout<<"What Column do you want?: "<<endl;
  cout<<"[a] Column A              [d] Column D"<<endl;
  cout<<"[b] Column B              [e] Column E"<<endl;
  cout<<"[c] Column C              [f] Column F"<<endl;
  cin>>y;
  switch (y)
  {case 'a': c=0; z='A'; reserveconfi(); break;
	case 'b': c=1; z='B'; reserveconfi(); break;
	case 'c': c=2; z='C'; reserveconfi(); break;
	case 'd': c=3; z='D'; reserveconfi(); break;
	case 'e': c=4; z='E'; reserveconfi(); break;
	case 'f': c=5; z='F'; reserveconfi(); break;
	default: error();
		 cin>>y;
		 switch (y)
		 {case 'b': column(); break;}
		 break;}
return 0;
}

int reserveconfi()
{seatplan();
cout<<endl;
cout<<"You have reserved for: ";
if (area==0)
  {cout<<"FIRST CLASS SEAT"<<endl;}
else if (area==1)
  {cout<<"ECONOMY CLASS SEAT"<<endl;
	cout<<"                        Non-Smoking Area"<<endl;}
else if (area==2)
  {cout<<"ECONOMY CLASS SEAT"<<endl;
	cout<<"                        Smoking Area"<<endl;}
cout<<"You have chosen seat position: ";
	 cout<<"Row "<<r<<" "<<"Column "<<z<<endl;
	 cout<<"[a] Continue"<<endl;
	 cout<<"[b] Change"<<endl;
	 cin>>y;
	 switch (y)
	  {case 'a': reserve(); break;
		case 'b': tickettype(); break;
		default: error();
			 cin>>y;
			 switch(y)
		{case 'b': reserveconfi(); break;}
			 break;
  }
return 0;
}

int reserve()
{seatplan();
for (p=0;p<num;p++)
{if ((m[p]==r)&&(n[p]==c))
	{x2=c;
	x1=r;}
}
taken();
return 0;}


int taken()
{if ((x1==r)&&(x2==c))
{cout<<"Sorry! Seat is already taken. Sorry!"<<endl;}
else
{str[r-1][c]='X';
reserved();}
return 0;
}

int reserved()
{seatplan();
cout<<"You Have Finally Reserved The Seat: "<<endl;
cout<<"Row "<<r<<" "<<"Column "<<z<<endl;
cout<<"Thank You!";
for (x=0;x<1;x++)
{m[t]=r;
n[t]=c;
t++;}
return 0;
}



int again()
{do
{tickettype();
cout<<endl<<endl<<"Want to Reserve Again? (y/n)";
cin>>y;
}
while (y=='y');
return 0;
}

i have this code....

(
when i enter row which is not the limit point it appears to have a bug...
)

example i enter 3 from the limit [1-2] and i enter it 5 times.....

it keeps on asking me 5 times of the column....

where is the bug on my code....

The problem is the recursive call at line 103 (as posted above). Change that to a loop instead of doing recursion.

if (area==0)
{
    r = 0;
    while( r < 1 || r > 2)
    {
        cout<<"(First Class Passengers May Only Choose Row[1-2]):";
        cin>>r;
    }
}

And it would help if you would use a better coding style -- there is nothing wrong with being very liberal with spaces and lines because it make the code a lot easier to read and understand.

it also has error.....

am i going to change the code in 103

with the code you give????

am i going to change the code in 103

with the code you give????

You have to do something similar in all three cases -- lines 98, 103, and 108

>>it also has error.....
What error ?

i had change the 3 lines yet it also has error.....

is there anything i need to change on the code you had given???

This article has been dead for over six months. Start a new discussion instead.