1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <string>
#include <climits>
using namespace std;
const int NUM_MONTHS = 12;
constexpr int MAXROWS{ 12 }, MAXCOLS{ 2 };
const string months[NUM_MONTHS]
{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
using MYLIST = int[MAXROWS][MAXCOLS];
void getData(MYLIST& myList); // <--- No need to pass a global variable.
int main()
{
MYLIST myList{}; // <--- ALWAYS initialize your variables.
getData(myList);
// A fair C++ replacement for "system("pause")". Or a way to pause the program.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0; // <--- Not required, but makes a good break point.
}
void getData(MYLIST& myList)
{
const std::string PROMPTS[]{ "highest", "lowest " }; // <--- Switch names if you want "lowest" first.
// Same thing for line 46 if you want to use it.
for (int row = 0; row < MAXROWS; row++)
{
std::cout << '\n';
for (int col = 0; col < MAXCOLS; col++)
{
std::cout << " Enter the " << PROMPTS[col] << " temperature for the month of " << months[row] << ": ";
//std::cout << " Enter the " << (col ? " lowest " : "highest ") << "temperature for the month of " << months[row] << ": ";
std::cin >> myList[row][col];
}
}
}
|