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;

#include<stdio.h>
#defineMaX6

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.

Recommended Answers

All 2 Replies

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<iostream>
#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;
}

Is this program to be made in C or C++? Because you posted in the C++ forum, but your code appears to be C

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.