Could you please refer to the code below and guide me as to how that error could be resolved?
///Listing 2-1
///A program that checks that the number the user input fits within a C++ integer variable
#include <iostream>
#include <limits>
using namespace std;
int main()
{
int min{ std::numeric_limits<int>::max() }; //<-error
int max{ std::numeric_limits<int>::min() }; //in min{} and the min function in max{}
bool any(false); //Variable initializations
int x;
while (std::cin >> x ) //This loop executes with input provided by the user
{
any = true;
if (x<min) //Evaluates user input against min value integers can have
min = x;
if (x)
max = x;
}
if (any) //This will execute if the user entered something
std::cout << "min = " << min << "\nmax = " << max << '\n'; //This will print the min value
} //and the max value on a new line
It appears that you are using an outdated compiler; update to a newer version.
Temporary fix (old compiler):
1 2 3 4 5
// Lines 11, 12
// int min{ std::numeric_limits<int>::max() }; //<-error
int min = std::numeric_limits<int>::max() ;
// int max{ std::numeric_limits<int>::min() }; //in min{} and the min function in max{}
int max = std::numeric_limits<int>::min() ;
Consider declaring min and max as const objects. constint min = ...