0

I'm getting errors on lines 8 & 43. I can't figure out what I'm doing wrong here (besides beating my head against the desk.)

#include <iostream>
using namespace std;

{
 try
    {
    if (num1 < 0) throw low;
    if (num2 < 0) throw low;
    if (num3 < 0) throw low;
    if (num4 < 0) throw low;
    if (num1 > 100) throw high;
    if (num2 > 100) throw high;
    if (num3 > 100) throw high;
    if (num4 > 100) throw high;

    catch (...)
    {
    cout << "Number out of range." << 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;


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


 return 0;
}
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by SpS
0

Either make try block inside main...or call a function from main which contains you try block...what are low, high...u haven't declared them anywhere...where are u asking for values of num1, num2...try reading the book again

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.