C/C++

Программирование в C++, проблема с дополнительной функцией.

Я программу написал, а она не работает (не запускается). Пожалуйста, скажите, что я сделал не так? При компиляции пишет, что проблема во включении "func.h", но как бы то ни было, если убрать или поменять "func.h", то тогда компиляция выдаёт каждую часть функции за ошибку. Вот код:

**
*** ***
96
создать func.h
или вообще убрать include func.h и две строчки ifndef и define и #endif (которого и нет)
Юрий Швец
Юрий Швец
25 445
Лучший ответ
#include <iostream>
#include <iomanip>
using namespace std;
size_t input_size(const char* msg) {
cout << msg;
size_t value;
cin >> value;
return value;
}
int** create_matrix(size_t n, size_t m) {
auto matrix = new (nothrow) int* [n];
if (matrix != nullptr) {
for (auto i = 0U; i < n; ++i) {
matrix[i] = new (nothrow) int[m];
if (matrix[i] == nullptr) {
for (auto j = 0U; j != i; ++j) {
if (matrix[j] != nullptr) {
delete[] matrix[j];
}
}
delete[] matrix;
matrix = nullptr;
break;
}
}
}
return matrix;
}
void destroy(int** matrix, size_t n) {
if (matrix != nullptr) {
for (auto i = 0U; i < n; ++i) {
if (matrix[i] != nullptr) {
delete[] matrix[i];
}
}
delete[] matrix;
matrix = nullptr;
}
}
void input_matrix(int** matrix, size_t n, size_t m) {
puts("Введите значения матрицы:");
for (auto i = 0U; i < n; ++i) {
for (auto j = 0U; j < m; ++j) {
cin >> matrix[i][j];
}
}
system("cls");
}
void output_matrix(int** matrix, size_t n, size_t m, streamsize w = 4) {
puts("Дана матрица: \n");
for (auto i = 0U; i < n; ++i) {
for (auto j = 0U; j < m; ++j) {
cout << setw(w) << matrix[i][j];
}
puts("");
}
puts("");
}
double multiply(int** matrix, size_t n, size_t c) {
auto result = 1.;
--c;
for (auto i = 0U; i < n; ++i) {
if (matrix[i][c] > 0) {
result *= matrix[i][c];
}
}
return result;
}
int main() {
system("chcp 1251 > nul");
auto n = input_size("Количество строк: ");
auto m = input_size("Количество столбцов: ");
auto matrix = create_matrix(n, m);
if (matrix != nullptr) {
input_matrix(matrix, n, m);
output_matrix(matrix, n, m);
auto c = 0U;
do {
c = input_size("Номер столбца: ");
} while (c - 1 >= m);
auto result = multiply(matrix, n, c);
cout << "Произведение: " << result << '\n';
}
destroy(matrix, n);
system("pause > nul");
}
Алексей Пагин
Алексей Пагин
52 575