You declare your variable res to be of the type airline (a structure type). Later on you try to use the array subscript operator (operator[]) on this structure. Since res isn't an array (or a class implementing the operator), the compiler will complain that you cannot use that operator on your variable. An example of what you might have intended:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int main()
{
/* Our variables */
airline* res; //We will store our values in here later on
int n; //The number of passengers
/* Get some value into n (like you did in your original code) */
...
/* Allocate enough airline structures for all passengers */
res = new airline[n]; //Allocate n airline structures
/* Use our values (like you did in your original code) */
...
/* Free the allocated airline structures */
delete[] res;
}
|
Don't forget to check for an allocation failure when using new, and don't forget to call delete when you're done with your values.
Another detail, try not to use
#include <conio.h>
. It's a non portable header file. Clearing the screen isn't necessary in most cases, and if it
really is necessary (think about console games like snake or pacman), then implement it yourself. Using clrscr reduces portability and the function, meaning quite a few people on this forum wouldn't be able to compile your code.
Also, try to use code tags from now on, it greatly improves readability and thus your chances at getting an answer to your topic.