Hi there,
Please remain polite, Mr. ToniAz was only trying to help and he made some good points.
First off, I would replace
printf()
with
std::cout <<
and
scanf()
with
std::cin >>
the former are C functions, the latter are C++ objects and are thus preferred.
So, you have displayed your menu, that's a start.
I'm just going to focus on that for now, we'll do the rest from the ground up so you understand what we're doing.
So, after some modification,this is what we have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
# define MAX 50 //max array size
int main()
{
int arr[MAX];
char choice;
std::cout << "MENU\n\n";
std::cout <<"F.Fill\nP. Print\nS. Sort\nQ. Query\nZ. Terminate\n";
std::cout <<"Please enter the option you selected: ";
std::cin >>char;
return 0;
}
| |
Now we have to evaulate the user's choice, which is now stored in char.
This is best done using a switch-statement ( http://cplusplus.com/doc/tutorial/control/#switch ) like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
switch (choice)
{
case 'F':
//do Filling here
break;
case 'P':
//do printing here
break;
case 'Q':
//do querying here
break;
case 'Z':
//exit here
break;
default: //if choice was none of the above
std::cout << "\nInvalid input - please try again.";
//show the menu again
}
| |
The best way to continue from that is to start with making a separate function that will fill an array, which is then called like so in the switch statement:
1 2 3
|
case 'F':
fill_array(int& array[]);
break;
| |
So, try and put that switch statement in the main function above and writing that fill function.
Once it is filled we can print and query it, so that's half the work done.
On a sidenote, defining TRUE and FALSE is really unnecessary, you can just use
true
and
false
in your code.
All the best,
NwN