main.cpp x 8 Console Shell vall MA > make -s cout « "How many columns do you want to display the numbers?\n"; cin >> width; 17 18 > ./main Hello World! cout « endl; for (int i = 0; i < limit; i++) { random_number[i]=rand() % MAX; 19 20 Enter a number between 1 and 100 21 20 22 How many columns do you want to display the numbers? 23 for (int i = e; i < limit; i+) { if (i s width == 0) { 24 25 21 24 36 16 30 26 cout « endl; 20 39 28 46 27 17 28 13 47 36 cout « setw(5) <« random_number(i]: cout « setw(5); 28 43 31 29 Amount of Odd numbers generated: 10 30 31 int even; Amount of Even numbers generated: 10 int odd; for (int i = 0; i« limit; i++) { 32 33 *1ト
main.cpp x 8 Console Shell vall MA > make -s cout « "How many columns do you want to display the numbers?\n"; cin >> width; 17 18 > ./main Hello World! cout « endl; for (int i = 0; i < limit; i++) { random_number[i]=rand() % MAX; 19 20 Enter a number between 1 and 100 21 20 22 How many columns do you want to display the numbers? 23 for (int i = e; i < limit; i+) { if (i s width == 0) { 24 25 21 24 36 16 30 26 cout « endl; 20 39 28 46 27 17 28 13 47 36 cout « setw(5) <« random_number(i]: cout « setw(5); 28 43 31 29 Amount of Odd numbers generated: 10 30 31 int even; Amount of Even numbers generated: 10 int odd; for (int i = 0; i« limit; i++) { 32 33 *1ト
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Hi I need help please. My programs problem is that its supposed to tell me how many even integers were generated and how many odd, but its returning 1/2 of the limit instead.
![main.cpp x
Console
Shell
Files
cout << "How many columns do you want to display the numbers?\n";
cin >> width;
17
> make -s
C* main.cpp
> ./main
18
19
cout << endl;
Hello World!
20ν
for (int i = 0; i < limit; i++) {
Enter a number between 1 and 100
20
21
random_number[i]=rand () % MAX;
22
How many columns do you want to display the numbers?
23
for (int i = 0; i < limit; i++) {
0) {
24 v
25 v
if (i % width ==
21
24
36
16
30
26
cout << endl;
20
39
28
46
4
27
17
28
13
47
36
28
cout <« setw ( 5) << random_number[i];
43
31
29
cout << setw(5);
Amount of Odd numbers generated:
10
30
31
int even;
Amount of Even numbers generated:
10
int odd;
> 0
32
33 ▼
for (int i = 0; i < limit; i++) {
34
35 v
if (i % 2
0) {
==
36
even++;
37
38 v
else if (!i % 2 == 0) {
39
odd++;
40
41
cout << end1 < "Amount of Odd numbers generated:\t" << odd << endl;
"Amount of Even numbers generated:\t" << even << endl;
42
43
cout << endl <<
44
45
46
47
...](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F46c0fb16-724b-4726-818c-9156075ac6cc%2Fc8044489-8d17-41d4-a8d1-9782f45d0605%2F3ge0mgi_processed.jpeg&w=3840&q=75)
Transcribed Image Text:main.cpp x
Console
Shell
Files
cout << "How many columns do you want to display the numbers?\n";
cin >> width;
17
> make -s
C* main.cpp
> ./main
18
19
cout << endl;
Hello World!
20ν
for (int i = 0; i < limit; i++) {
Enter a number between 1 and 100
20
21
random_number[i]=rand () % MAX;
22
How many columns do you want to display the numbers?
23
for (int i = 0; i < limit; i++) {
0) {
24 v
25 v
if (i % width ==
21
24
36
16
30
26
cout << endl;
20
39
28
46
4
27
17
28
13
47
36
28
cout <« setw ( 5) << random_number[i];
43
31
29
cout << setw(5);
Amount of Odd numbers generated:
10
30
31
int even;
Amount of Even numbers generated:
10
int odd;
> 0
32
33 ▼
for (int i = 0; i < limit; i++) {
34
35 v
if (i % 2
0) {
==
36
even++;
37
38 v
else if (!i % 2 == 0) {
39
odd++;
40
41
cout << end1 < "Amount of Odd numbers generated:\t" << odd << endl;
"Amount of Even numbers generated:\t" << even << endl;
42
43
cout << endl <<
44
45
46
47
...
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education