1

I am very new to c++, and I am doing this simple homework where I need to find max and min values, it keeps giving me expected unqualified id error. Here is the code, thanks a lot.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int min(int a, int b, int c, int d)
{
    int result = a;
    if (b < result) result = b;
    if (c < result) result = c;
    if (d < result) result = d;
    return result;
}

int main()
{
    int x;
    x = min(2,6,3,4);
    cout << " The result is " << x;
}

int max( int a, int b, int c, int d); #expected unqualified id
{
    int max = a;
    if (b > result) result = b;
    if (c > result) result = c;
    if (d > result) result = d;
    return max;
}

int main1()
{
    int x;
    x = min(2,6,3,4);
    cout << " The result is " << x;
}
Yunxiao Jia
  • 39
  • 1
  • 7
  • 2
    Please [edit] your question to include the EXACT error – Tas Feb 05 '18 at 01:55
  • Note that your error is very likely to do with your use of `using namespace std` (so you can see [why it's a bad idea](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)) and your vague function names. – Tas Feb 05 '18 at 01:56

1 Answers1

2
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int result;

int min(int a, int b, int c, int d)
{
    result = a;
    if (b < result) result = b;
    if (c < result) result = c;
    if (d < result) result = d;
    return result;
}

int max(int a, int b, int c, int d)
{
    result = a; //before-edit "int max = a"
    if (b > result) result = b;
    if (c > result) result = c;
    if (d > result) result = d;
    return result;
}

int main()
{
    int Min,Max;
    Min = min(2,6,3,4);
    cout << " The result for minimum is " << Min << endl;
    Max = max(2,6,3,4);
    cout << " The result for maximum is " << Max;
}

On the max(a,b,c,d) function you only pass the value of a and it didn't go through the if else cases like your min(), don't be lazy to review your code after copy & paste.

The reason of why you getting the error of expected unqualified id due to you have include a semi-colon at the end of this line.

int max(int a, int b, int c, int d);
{
    ...
}
JaxLee
  • 106
  • 1
  • 7