It seems to do without bool , everything worked, now some kind of trouble ...

#include <cstdlib> #include <iostream> #include <ctime> #include <cmath> using namespace std; bool chet(int); void vyvod(int mas[], int a) { int i; for (i = 0; i < a; i++) cout << mas[i] << " "; cout << endl; } int nechetn(int mas[], int a, int nech[], int u) { int i, neb = 0; for (i = 0; i < a; i++) { if (!(chet(mas[i]))) { nech[neb] = mas[i]; neb++; } } return neb; } int chetn(int mas[], int a, int ch[], int u) { int i, b = 0; for (i = 0; i < a; i++) { if (chet(mas[i])) { ch[b] = mas[i]; b++; } } return b; } int main() { int i, A, B, chetn, nechetn, kchet, knechetn; int mas[30], ch[30], nech[30], chet[30]; cout << "Диапазон" << endl; cout << "введите А: "; cin >> A; cout << "введите В: "; cin >> B; srand(time(NULL)); for (i = 0; i < 30; i++) mas[i] = rand() % (B - A + 1) + A; kchet = chetn(mas, 30, ch, 30); knechetn = nechetn(mas, 30, nech, 30); cout << "массив рандома: " << endl; vyvod(mas, 30); cout << "массив четных: " << endl; vyvod(ch, kchet); cout << "массив не четных: " << endl; vyvod(nech, knechetn); system("pause"); return 0; } bool chet(int a) { int i; if (a % 2 == 0) return true; return false; } 
  • Error where ? Which line? Why is this indicated in the question? - AnT
  • kchet = chetn (mas, 30, ch, 30); knechetn = nechetn (mas, 30, nech, 30); error cannot be used as a function both there and there - user319308
  • What is the purpose of the variable i in the function chet ? - AnT

1 answer 1

Get in the habit of giving different names to variables and functions. If you thoughtlessly give them the same name, then such errors will result. This is not prohibited, but it should be done with an understanding of what is happening.

In your main function, the names chetn and nechetn are variables of type int , not functions. And you are trying to "call" them as functions. What the compiler clearly told you.

  • Now I’ll edit another code, they aren’t announced there, but the error is Ms - user319308
  • @ VasyaPupkin Do not carry nonsense and invent fairy tales. It does not happen. If the error is "the same", then the error is really the same . - AnT