Hepl me and check mo code!

Arrays are filled by the user with numbers 1,2,3,4,5. It is necessary to deduce those arrays where there are numbers 3,4,5. And give as a number, for example 7 arrays with numbers 3,4,5.
I entered numbers in an array but some nonsense is deduced. Help!Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  #include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    const int del = 3;
    const int size = 5;
    int arr1[size];
    int arr2[size];
    int arr3[size];
    int arr4[size];
    int arr5[size]; 
    int arr6[size];
    int arr7[size];
    int arr8[size];
    int arr9[size];
    int arr10[size];
    int arr11[size];
    int arr12[size];
    int arr13[size];
    int arr14[size]; 
    int arr15[size]; 
   int i = 0;
  
   for (int i = 0; i < size; i++) {
       cout << "[  1 ]"  << ": ";
      
       cin >> arr1[i];
   }
   for (int i = 0; i < size; i++)
        
     {  cout << "[  2 ]" << ": ";
         cin >> arr2[i];
   }
   for (int i = 0; i < size; i++)
        
     { cout << "[  3 ]" << ": ";
        cin >> arr3[i];
   }
   for (int i = 0; i < size; i++)
        
     {  cout << "[  4 ]" << ": ";
        cin >> arr4[i];
   }
   for (int i = 0; i < size; i++)
     {         cout << "[  5 ]" << ": ";

       cin >> arr5[i];
   }
   for (int i = 0; i < size; i++)

   {       cout << "[  6 ]" << ": ";
       cin >> arr6[i];
   }
   for (int i = 0; i < size; i++)
           
       {   cout << "[  7 ]" << ": ";
           cin >> arr7[i];
   }
   for (int i = 0; i < size; i++)
      
    {   cout << "[  8 ]" << ": ";
       cin >> arr8[i];
   }
   for (int i = 0; i < size; i++)
       
    {  cout << "[  9 ]" << ": ";
       cin >> arr9[i];
   }
   for (int i = 0; i < size; i++)
      
    {   cout << "[  10 ]" << ": ";
       cin >> arr10[i];
   }
   for (int i = 0; i < size; i++)
      
    {   cout << "[  11 ]" << ": ";
       cin >> arr11[i];
   }
   for (int i = 0; i < size; i++)
       
    {  cout << "[  12 ]" << ": ";
       cin >> arr12[i];
   }
   for (int i = 0; i < size; i++)
      
    {   cout << "[  13 ]" << ": ";
       cin >> arr13[i];
   }
   for (int i = 0; i < size; i++)
       
     {  cout << "[  14 ]" << ": ";
       cin >> arr14[i];
   }
   for (int i = 0; i < size; i++)
      
     {        cout << "[  15 ]" << ": ";
       cin >> arr15[i];
    }

    
    
   for (int i = 0; i < size; ++i) {
       if (arr1[i] >= del)
            arr1[i] =1 ;
   }
   {
       if (arr2[i] >= del)
       cout << arr2[i] << endl;
   }
   { 
       if (arr3[i] >= del)
       cout << arr3[i] << endl;
   } 
   { 
       if (arr4[i] >= del)
       cout << arr4[i] << endl;
   }
   {
       if (arr5[i] >= del)
       cout << arr5[i] << endl;
   }
   {
       if (arr6[i] >= del)
           cout << arr6[i] << endl;
   }
   {
       if (arr7[i] >= del)
           cout << arr7[i] << endl;
   }
   {
       if (arr8[i] >= del)
           cout << arr8[i] << endl;
   }
   {
       if (arr9[i] >= del)
           cout << arr9[i] << endl;
   }
   {
       if (arr10[i] >= del)
           cout << arr10[i] << endl;
   }
   {
       if (arr11[i] >= del)
           cout << arr11[i] << endl;
   }
   {
       if (arr12[i] >= del)
           cout << arr12[i] << endl;
   }
   {
       if (arr13[i] >= del)
           cout << arr13[i] << endl;
   }
   {
       if (arr14[i] >=del)
           cout << arr14[i] << endl;
   }
   {
       if (arr15[i] >= del)
        cout << arr15[i] << endl;
    }
  
    cout << endl;

	return 0;
Do you mean 3 or 4 or 5 - or 3 and 4 and 5?
Hello chebyrek,

I am thinking this might work better for you to start with:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    const int del = 3;
    //const int size = 5;
    constexpr int MAXROWS{ 15 };
    constexpr int MAXCOLS{ 5 };

    int numArray[MAXROWS][MAXCOLS]{};

The 2D array would make life much easier. Consider what you would need if the number of arrays increased to 100. That would mean 85 additional lines to create the arrays and another 425 lines or maybe more for the for loops to fill each array.

A short nested for loop could fill the array with the least amount of work.

The for loop at line 104 works for just 1 array only.

From line 108 on the {} around the if statement are not needed. Your next problem:
1
2
if (arr2[i] >= del)
      cout << arr2[i] << endl;

Would actually look like:
1
2
if (arr2[0] >= del)
      cout << arr2[0] << endl;

And the rest of the if statements would be the same.

The "i" you are using here comes from line 24 which is set to (0) zero and never changes unless I missed something. If you are thinking that you are using the "i" from the for loop you are not. That "i" was destroyed when the for loop ended.

Some things to consider to shorten your code and make it easier to work with.

Andy
If you mean contains any of the numbers, then consider:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <algorithm>

int main()
{
	const size_t no_array {15};
	const size_t size {5};
	const int valid[] {3, 4, 5};

	int arrs[no_array][size] {};
	size_t cnt {};

	for (size_t a = 0; a < no_array; ++a) {
		std::cout << "Please enter " << size << " numbers for array " << a + 1 << " : ";

		for (size_t n = 0; n < size; ++n)
			std::cin >> arrs[a][n];

		cnt += std::find_first_of(std::begin(arrs[a]), std::end(arrs[a]), valid, valid + std::size(valid)) != std::end(arrs[a]);
	}

	std::cout << cnt << " arrays contain at least one of the numbers\n";
}


If you mean contains all of the numbers, then consider:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <algorithm>

int main()
{
	const size_t no_array {15};
	const size_t size {5};
	const int valid[] {3, 4, 5};

	int arrs[no_array][size] {};
	size_t cnt {};

	for (size_t a = 0; a < no_array; ++a) {
		std::cout << "Please enter " << size << " numbers for array " << a + 1 << " : ";

		for (size_t n = 0; n < size; ++n)
			std::cin >> arrs[a][n];

		bool fnd {true};

		for (int n : valid)
			fnd &= std::find(std::begin(arrs[a]), std::end(arrs[a]), n) != std::end(arrs[a]);

		cnt += fnd;
	}

	std::cout << cnt << " arrays contain all of the numbers\n";
}

Last edited on
Need to display the entire number of arrays that contain only 3,4,5. And count their number.
Thanks to everyone who gave ideas and codes for the solution.
If you have more ideas, I'll be glad to do everything.
You still haven't said whether it needs to contain all these numbers or just any of them or only any combination of these numbers.

So what about:

1 2 3 3 3
1 2 3 4 5
3 3 3 4 5
4 4 4 4 4

etc???
Last edited on
Topic archived. No new replies allowed.