Hi. I'm doing an assignment in C++ that mainly deals with structs and arrays. They are not my strong point right now. I constructed this code below with a friend who is MIA at the moment. The code outputs what I want, but he included vectors. I am not allowed to use vectors yet since I barely began OOP, so there are some functions that I am unsure of adjusting/omitting correctly. I tried to abbreviate it somewhat for reading ease, so hopefully it still makes sense.
#include <iostream>
void printNumbers( constint* numbers, constint current_size )
{
for ( int i = 0; i < current_size; ++i )
printNumber( numbers[ i ] );
}
int main( void )
{
constint MAX_SIZE = 16;
int numbers[ MAX_SIZE ];
int current_size = 0;
while ( /* the user wants to add a number*/ )
{
if ( current_size < MAX_SIZE )
{
numbers[ current_size ] = a_function_returning_an_int();
++current_size;
}
else
{
// handle the fact that there is no space
// at this point, just say that there isn't space and quit the loop
}
}
printNumbers( numbers, current_size );
return 0;
}
Aside from the conspicuous typo's Lowest0ne about has your answer. Another solution would be dynamically allocating the array of orders with the 'new' operator. I'm self taught and I often forget in what progression universities traditionally teach stuff in. But I would assume that the STL containers would precede dynamic allocation in any reasonable setting that focused on OOP and RAII. So I'll only post my suggestion upon request.
Yeah, before you noted the typos I had that function named printNumber, so a little misleading indeed.
I originally had used jksdk4's class names and didn't want to write the code to print a single menuItemType ( printMenuItemTypes() calls printMenuItemType() many times ). Then I decided that it would be more of a learning exercise if jksdk4 couldn't just do a copy/paste and switched it to int.