#include <iostream>
using namespace std;
int main()
{
cout << "Input the number of real numeric: ";
int num = 0;
// перехват исключения, если введено не число
cin.exceptions(istream::failbit | istream::badbit);
try
{
cin >> num;
}
catch (...)
{
cout << "Input is not a real number" << endl;
return -1;
}
int input, sum = 0, devel = num;
do
{
cout << "Input real numeric: ";
try
{
cin >> input;
}
catch (...)
{
cout << "Input is not a real number" << endl;
return -1;
}
sum += input;
}
while (--num > 0);
cout << "Average: " << sum / devel << endl;
return 0;
}
Input the number of real numeric: 3
Input real numeric: 1
Input real numeric: 3
Input real numeric: 5
Average: 3
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.