### Homework help c++ Structs

This is my code for homework. I am doing a lot of stuff wrong but don't know exactly what. Any suggestions?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210`` ``````#include using namespace std; const MAX = 4; // STRUCT DECLARATION struct Airplanes { string airline[MAX]; string arrivingFrom[MAX]; }; // END STRUCT DECLARATION //FUNCTIONS string addNewArrival(string); //Organizes new plane to last place in array bool newArrival(int totalArrivals[MAX]); bool fullTerminal(int totalArrivals[MAX]); //Test if there are new arrivles or if full //MAIN BEGINS int main() { Airplanes air; int totalArrivals[MAX]; int addingNewArrival; bool newArrivals; bool full; int i; //START SETTING DEFAULTS for(i = 0; i < MAX; i++) { totalArrivals[i] = 0; } for(i = 0; i < MAX; i++) { air.airline[i] = ""; air.arrivingFrom[i] = ""; } //END SETTING DEFAULT newArrivals = newArrival(totalArrivals[]); if(newArrivals == true) { cout << "There are no new Arrivals" << endl; } else { cout << "There are new arrivals" << endl; } addingNewArrival = addNewArrival(totalArrivals[]); newArrivals = newArrival(totalArrivals[]); cout << "newArrivals" << endl; full = fullTerminal(totalArrivals[]); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } air.airline[2] = "Air Canada"; air.airline[3] = "Delta"; air.arrivingFrom[2] = "Toronto"; air.arrivingFrom[3] = "Minneapolis"; addingNewArrival = addNewArrival(int totalArrivals[MAX]); newArrival = newArrivals(totalArrival[]); if(newArrival == true) { cout << "There are new arrivals" << endl; } else { cout << "There are no new arrivals" << endl; } full = fullTerminal(totalArrivals[MAX]) if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } } //MAIN ENDS string addNewArrival(int totalArrivals[MAX]) { int i; int count =0; air.airline[0] = "WestJet"; air.arrivingFrom[0] = "Calgary"; air.airline[1] = "United"; air.arrivingFrom[1] = "Chicago"; for(i = 0; i < MAX; i++) { if(air.airline[i] != "") { count ++; } } while(i <= count) { if(totalArrivals[i] ==0) { totalArrivals[i] = totalArrivals[i] + 1; } } } bool newArrival(int totalArrivals[MAX]) { int count; int i for(i = 0; i < MAX; i++) { if(totalArrivals[i] ==0) { count ++ } } if(count == 4) { return true; } else { return false; } } bool fullTerminal(int totalArrivals[MAX]) { int count; for(i = 0; i < MAX; i ++) { if(totalArrivals[i] >0) { count ++; } } if(count == 4) { return true; } else { return false; } } ``````
What does it do that you don't want to, and what does it not do that you do want it to? Without knowing what you're trying to do, it's very hard to tell you how to fix it.
I'm getting like 20+ errors. I must be passing things wrong and defining stuff wrong. But I'm not really sure what exactly is wrong? It must be structured wrong.
Post the errors son.
After some fixing..

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211`` ``````#include using namespace std; const MAX = 4; // STRUCT DECLARATION struct Airplanes { string airline[MAX]; string arrivingFrom[MAX]; }; // END STRUCT DECLARATION //FUNCTIONS string addNewArrival(string); //Organizes new plane to last place in array bool newArrival(int totalArrivals[]); bool fullTerminal(int totalArrivals[]); //Test if there are new arrivles or if full //MAIN BEGINS int main() { Airplanes air; int totalArrivals[MAX]; int addingNewArrival; int x; bool newArrivals = false; bool full = false; int i; //START SETTING DEFAULTS for(i = 0; i < MAX; i++) { totalArrivals[i] = 0; } for(i = 0; i < MAX; i++) { air.airline[i] = ""; air.arrivingFrom[i] = ""; } //END SETTING DEFAULT newArrivals = newArrival(totalArrivals[]); if(newArrivals == true) { cout << "There are no new Arrivals" << endl; } else { cout << "There are new arrivals" << endl; } addingNewArrival = addNewArrival(); newArrivals = newArrival(totalArrivals[]); cout << "newArrivals" << endl; full = fullTerminal(totalArrivals[]); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } air.airline[2] = "Air Canada"; air.airline[3] = "Delta"; air.arrivingFrom[2] = "Toronto"; air.arrivingFrom[3] = "Minneapolis"; addingNewArrival = addNewArrival(int totalArrivals[MAX]); newArrival = newArrivals(totalArrival[]); if(newArrival == true) { cout << "There are new arrivals" << endl; } else { cout << "There are no new arrivals" << endl; } full = fullTerminal(totalArrivals[MAX]); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } } //MAIN ENDS string addNewArrival(int totalArrivals[]) { int i; int count =0; air.airline[0] = "WestJet"; air.arrivingFrom[0] = "Calgary"; air.airline[1] = "United"; air.arrivingFrom[1] = "Chicago"; for(i = 0; i < MAX; i++) { if(air.airline[i] != "") { count ++; } } while(i <= count) { if(totalArrivals[i] ==0) { totalArrivals[i] = totalArrivals[i] + 1; } } } bool newArrival(int totalArrivals[]) { int count; int i for(i = 0; i < MAX; i++) { if(totalArrivals[i] ==0) { count ++ } } if(count == 4) { return true; } else { return false; } } bool fullTerminal(int totalArrivals[]) { int count; for(i = 0; i < MAX; i ++) { if(totalArrivals[i] >0) { count ++; } } if(count == 4) { return true; } else { return false; } } ``````

ERRORS:

"A2BJ.cpp", line 55: Error: Operand expected instead of "]".
"A2BJ.cpp", line 55: Error: Formal argument totalArrivals of type int* in call to newArrival(int*) is being passed int.
"A2BJ.cpp", line 65: Error: Too few arguments in call to "addNewArrival(std::basic_string<char, std::char_traits<char>, std::allocator<char>>)".
"A2BJ.cpp", line 66: Error: Operand expected instead of "]".
"A2BJ.cpp", line 66: Error: Formal argument totalArrivals of type int* in call to newArrival(int*) is being passed int.
"A2BJ.cpp", line 69: Error: Operand expected instead of "]".
"A2BJ.cpp", line 69: Error: Formal argument totalArrivals of type int* in call to fullTerminal(int*) is being passed int.
"A2BJ.cpp", line 102: Error: Badly formed expression.
"A2BJ.cpp", line 103: Error: totalArrival is not defined.
"A2BJ.cpp", line 103: Error: Operand expected instead of "]".
"A2BJ.cpp", line 103: Error: Only a function may be called.
"A2BJ.cpp", line 104: Error: The operation "bool(*)(int*) == bool" is illegal.
"A2BJ.cpp", line 113: Error: Formal argument totalArrivals of type int* in call to fullTerminal(int*) is being passed int.
"A2BJ.cpp", line 152: Error: air is not defined.
"A2BJ.cpp", line 152: Error: Badly formed expression.
"A2BJ.cpp", line 153: Error: air is not defined.
"A2BJ.cpp", line 153: Error: Badly formed expression.
"A2BJ.cpp", line 154: Error: air is not defined.
"A2BJ.cpp", line 154: Error: Badly formed expression.
"A2BJ.cpp", line 155: Error: air is not defined.
"A2BJ.cpp", line 155: Error: Badly formed expression.
"A2BJ.cpp", line 159: Error: air is not defined.
"A2BJ.cpp", line 159: Error: Badly formed expression.
"A2BJ.cpp", line 172: Error: "addNewArrival(int*)" is expected to return a value.
"A2BJ.cpp", line 181: Error: Use ";" to terminate declarations.
Compilation aborted, too many Error messages.
okay ill take out as many as i can.

--"A2BJ.cpp", line 55: Error: Operand expected instead of "]".
I think this is because when passing an array as a parameter, you dont need the [].

next one is something about pointers, i still need to study pointers so no help there.

--"A2BJ.cpp", line 65: Error: Too few arguments in call to "addNewArrival(std::basic_string<char, std::char_traits<char>, std::allocator<char>>)".
This is easy, you arent passing in enough arguments

See the first error for all the other ones that expect an operand instead of "]"

uhh im used to working with classes so im not positive, but i think another problem your having is that your using variables that are declared in main. Either pass the variables to the functions making use of the "&" or declare the variables globally, or outside of main.

Thanks that helped a lot!
After some more fixing I only have 10 ERRORS!!! yay

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213`` ``````#include using namespace std; const MAX = 4; // STRUCT DECLARATION struct Airplanes { string airline[MAX]; string arrivingFrom[MAX]; }; // END STRUCT DECLARATION //FUNCTIONS string addNewArrival(string); //Organizes new plane to last place in array bool newArrival(int totalArrivals[]); bool fullTerminal(int totalArrivals[]); //Test if there are new arrivles or if full //MAIN BEGINS int main() { Airplanes air; int totalArrivals[MAX]; int addingNewArrival; int x; bool newArrivals = false; bool full = false; int i; //START SETTING DEFAULTS for(i = 0; i < MAX; i++) { totalArrivals[i] = 0; } for(i = 0; i < MAX; i++) { air.airline[i] = ""; air.arrivingFrom[i] = ""; } //END SETTING DEFAULT newArrivals = newArrival(totalArrivals); if(newArrivals == true) { cout << "There are no new Arrivals" << endl; } else { cout << "There are new arrivals" << endl; } addingNewArrival = addNewArrival(totalArrivals); newArrivals = newArrival(totalArrivals); cout << "newArrivals" << endl; full = fullTerminal(totalArrivals[]); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } air.airline[2] = "Air Canada"; air.airline[3] = "Delta"; air.arrivingFrom[2] = "Toronto"; air.arrivingFrom[3] = "Minneapolis"; addingNewArrival = addNewArrival(int totalArrivals[MAX]); newArrival = newArrivals(totalArrivals[]); if(newArrival == true) { cout << "There are new arrivals" << endl; } else { cout << "There are no new arrivals" << endl; } full = fullTerminal(totalArrivals[MAX]); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } } //MAIN ENDS string addNewArrival(int totalArrivals[]) { Airplanes air; int i; int count =0; air.airline[0] = "WestJet"; air.arrivingFrom[0] = "Calgary"; air.airline[1] = "United"; air.arrivingFrom[1] = "Chicago"; for(i = 0; i < MAX; i++) { if(air.airline[i] != "") { count ++; } } while(i <= count) { if(totalArrivals[i] ==0) { totalArrivals[i] = totalArrivals[i] + 1; } } } bool newArrival(int totalArrivals[]) { int count =0; int i; for(i = 0; i < MAX; i++) { if(totalArrivals[i] ==0) { count ++; } } if(count == 4) { return true; } else { return false; } } bool fullTerminal(int totalArrivals[]) { int count= 0; int i; for(i = 0; i < MAX; i ++) { if(totalArrivals[i] >0) { count ++; } } if(count == 4) { return true; } else { return false; } } ``````

ERRORS:
"A2BJ.cpp", line 65: Error: Formal argument 1 of type std::basic_string<char, std::char_traits<char>, std::allocator<char>> in call to addNewArrival(std::basic_string<char, std::char_traits<char>, std::allocator<char>>) is being passed int*.
"A2BJ.cpp", line 65: Error: Cannot assign std::basic_string<char, std::char_traits<char>, std::allocator<char>> to int.
"A2BJ.cpp", line 69: Error: Operand expected instead of "]".
"A2BJ.cpp", line 69: Error: Formal argument totalArrivals of type int* in call to fullTerminal(int*) is being passed int.
"A2BJ.cpp", line 102: Error: Badly formed expression.
"A2BJ.cpp", line 103: Error: Operand expected instead of "]".
"A2BJ.cpp", line 103: Error: Only a function may be called.
"A2BJ.cpp", line 104: Error: The operation "bool(*)(int*) == bool" is illegal.
"A2BJ.cpp", line 113: Error: Formal argument totalArrivals of type int* in call to fullTerminal(int*) is being passed int.
"A2BJ.cpp", line 174: Error: "addNewArrival(int*)" is expected to return a value.

`const MAX = 4;`
What kind of object is MAX? The compiler needs to know.

`full = fullTerminal(totalArrivals[]);`
Stop doing this. There is no such object as `totalArrivals[]` so you cannot pass it to a function. There is something called `totalArrivals`.

`addingNewArrival = addNewArrival(int totalArrivals[MAX]);`

`int totalArrivals[MAX])` is an attempt to create an array of type int. The compiler expects to find the name of the onject you want to pass into the function. This is just plain wrong.

`newArrival = newArrivals(totalArrivals[]);`
Stop doing this. There is no such object as `totalArrivals[]` so you cannot pass it to a function. There is something called `totalArrivals`. Also, newArrival is the name of function, newArrivals in an object. This kind of mix up is why it's a terrible idea to give your functions and objects almost identical names.

`if(newArrival == true)`
newArrival is a function name. How can you compare the name of a function to the value true? It makes no sense.

Last edited on
Thanks, that totally helped a lot! After fixing some more stuff, I have finally broke it down into 2 errors. All issues with addNewArrival.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225`` ``````/* . . . . . . */ #include using namespace std; const int MAX = 4; // STRUCT DECLARATION struct Airplanes { string airline[MAX]; string arrivingFrom[MAX]; }; // END STRUCT DECLARATION //FUNCTIONS int addNewArrival(string); //Organizes new plane to last place in array bool newArrival(int totalArrivals[]); bool fullTerminal(int totalArrivals[]); //Test if there are new arrivles or if full //MAIN BEGINS int main() { Airplanes air; int totalArrivals[MAX]; int addingNewArrival =0; bool newArrivals = false; bool full = false; int i; //START SETTING DEFAULTS for(i = 0; i < MAX; i++) { totalArrivals[i] = 0; } for(i = 0; i < MAX; i++) { air.airline[i] = ""; air.arrivingFrom[i] = ""; } //END SETTING DEFAULT newArrivals = newArrival(totalArrivals); if(newArrivals == true) { cout << "There are no new Arrivals" << endl; } else { cout << "There are new arrivals" << endl; } addingNewArrival = addNewArrival(totalArrivals); newArrivals = newArrival(totalArrivals); cout << "newArrivals" << endl; full = fullTerminal(totalArrivals); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } air.airline[2] = "Air Canada"; air.airline[3] = "Delta"; air.arrivingFrom[2] = "Toronto"; air.arrivingFrom[3] = "Minneapolis"; addingNewArrival = addNewArrival(totalArrivals); newArrivals = newArrival(totalArrivals); if(newArrivals == true) { cout << "There are new arrivals" << endl; } else { cout << "There are no new arrivals" << endl; } full = fullTerminal(totalArrivals); if(full == true) { cout << "The terminal is full" << endl; } else { cout << "The terminal is not full" << endl; } cout << "Searching for Air Canada plane from Toronto " << endl; for(i = 0; i < MAX; i++) { if(air.arrivingFrom[i] == "Toronto") { cout << "There is a plane from toronto in" << endl; } if(air.airline[i] == "Air Canada") { cout << "It is from Air Canada" << endl; } else { cout << "It is not from Air Canada" << endl; } } } //MAIN ENDS int addNewArrival(int totalArrivals[]) { Airplanes air; int i; int count =0; air.airline[0] = "WestJet"; air.arrivingFrom[0] = "Calgary"; air.airline[1] = "United"; air.arrivingFrom[1] = "Chicago"; for(i = 0; i < MAX; i++) { if(air.airline[i] != "") { count ++; } } while(i <= count) { if(totalArrivals[i] ==0) { totalArrivals[i] = totalArrivals[i] + 1; } } return 1; } bool newArrival(int totalArrivals[]) { int count =0; int i; for(i = 0; i < MAX; i++) { if(totalArrivals[i] ==0) { count ++; } } if(count == 4) { return true; } else { return false; } } bool fullTerminal(int totalArrivals[]) { int count= 0; int i; for(i = 0; i < MAX; i ++) { if(totalArrivals[i] >0) { count ++; } } if(count == 4) { return true; } else { return false; } } ``````

ERRORS:

"A2BJ.cpp", line 64: Error: Formal argument 1 of type std::basic_string<char, std::char_traits<char>, std::allocator<char>> in call to addNewArrival(std::basic_string<char, std::char_traits<char>, std::allocator<char>>) is being passed int*.
"A2BJ.cpp", line 101: Error: Formal argument 1 of type std::basic_string<char, std::char_traits<char>, std::allocator<char>> in call to addNewArrival(std::basic_string<char, std::char_traits<char>, std::allocator<char>>) is being passed int*.
2 Error(s) detected.
Last edited on
When you pass an array like that, I believe it's in the form of a pointer to the first element of the array.
`addingNewArrival = addNewArrival(totalArrivals);`

What did you tell the compiler about this function? int addNewArrival(string);
So you told it that addNewArrival is a function that takes a string object.

What are you trying to pass it? totalArrivals.
What kind of object is totalArrivals? An int array.
Is that the same as a string? No.
Topic archived. No new replies allowed.