I'm getting a parse error before '<' on line 26. What's going on that I don't seem to be seeing here?

#include <iostream>
using std::cin;
using std::cout;
using std::endl;


int main()
{

int num1, num2, num3, num4;
int avg;

cout << "Enter four numbers to be averaged." << endl;
cout << "\nNumbers must be between 0 and 100." << endl;

 while (cin >> num1 >> num2 >> num3 >> num4)
{
 try
    {
    avg = (num1 + num2 + num3 + num4)/4;
    cout << "The average is: " << avg << endl;
    }

    catch ( num1<0 & num2<0 & num3<0 & num4<0 )
      {
      cout << "Number(s) too low. " << endl;
      } 

      catch ( num1>100 & num2>100 & num3>100 & num4>100 )
      {
      cout << "Number(s) too high. " << endl;
      }

      cout << "Enter four numbers to be averaged." << endl;
      cout << "\nNumbers must be between 0 and 100." << endl;

}
     cout << endl;
 return 0;
}

Recommended Answers

All 3 Replies

You can't do this in catch

catch ( num1<0 & num2<0 & num3<0 & num4<0 )

How would I go about writing it so that it will catch if any of the four numbers are less than 0?

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.