Write a program that will take the sum of the odd-indexed array elements in array of 50 integers completely filled.  This is my C++ Codes but when I entered the 50 integers, the sum of the odd-indexed are wrong. Can you fix the errors? Please still use header files iostream header files. This is a topic under Data Structures: Arrays.

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
icon
Related questions
Question
100%

Problem:

Write a program that will take the sum of the odd-indexed array elements in array of 50 integers completely filled. 

This is my C++ Codes but when I entered the 50 integers, the sum of the odd-indexed are wrong. Can you fix the errors? Please still use header files iostream header files. This is a topic under Data Structures: Arrays.

//Start of program
#include <iostream>

using namespace std;

int main()
{
//Declare array and initialize variables
int a[50], sum = 0, i;

//Prompt the user
cout << "Enter 50 values of integer array: \n";

//For loop
for (i = 0; i < 50; i++)
{
cin >> a[i];
}

//Odd-indexed numbers
for (i = 0; i < 50; i++)
{
if (a[i] % 2 != 0) //If the remainder when element at i is divided by 2 yields a non-zero value
{
continue; //Iteration repeated wherein element at i is incremented and tested
}
sum += a[i]; //Statement executed and iteration continued
}

//Prompt the message with the sum of odd-indexed numbers
cout << "The sum of odd-indexed numbers are: " << sum << endl;

//End of program
return 0;
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education