No. But if you have multiple input loops like that, you should extract them into a function. That way you don't have to write the same code twice. Also note that there is a mistake in your original code: you cannot define a array using a variable as size - you need to allocate the array dynamically. Also you should check whether the size is in fact a meaningful value:
bool read_array(int*& arr, int& arr_size) {
bool result = false;
cin >> arr_size;
if (arr_size > 0 && arr_size < 100) {
arr = new int[arr_size];
for (int index = 0; index < arr_size; ++index) {
cin >> arr[index];
}
result = true;
}
return result;
}
int main () {
int* arr = nullptr; int a = 0; if (!read_array(arr, a) {
cout << "Failed to read first array" << endl;
a = 0; }
int* arr2 = nullptr;
int b = 0;
if (!read_array(arr2, b) {
cout << "Failed to read second array" << endl;
b = 0; }
return 0;
}