I had to create a program that has to work with an array of MAX temperatures, define a constant for the array size, use sort and search algoritms, and write a menu driven program for homework. I am stuck on what's next after the int declaration as such;


int main(void)

{ int temperatures[MAX]= {59,79,99,47,103,71};

Please help, I know I have to for loop it, but I'm stuck.

7 Years
Discussion Span
Last Post by Nick Evan

Don't use define.
Use this :

const unsigned int MAX_SIZE = 6;
int main(){ ... }

For sorting and searching use the stl sort and find method.

So to start have this :

#include<algorithm> //for search and sort methods

using namespace std;

int menu(); //returns a choice from sorting and/or searching

int main(){
  const unsigned int MAX_SIZE = 10;
  int Array[MAX_SIZE] = {0}; //set all elements to 0
   int choice = menu();
  if(choice == 1) { std::sort(Array, Array + MAX_SIZE ); }   //then display it
else if(choice == 2) { std::find(...) ; }
else;// print errror

return 0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.