The program displays the sum of element 2 and element 4 of an array. Identify if it contains any error. If yes, locate and state the error. 1 #include using namespace std; 3 void compTotal(int a[])( for (int i = 0; i < 10; i++) { a[i] = a[i] * 2; 4 7 8 10 int main () ( 11 int total = 0, arr[10] = (1,2,3,4,5,6,7,8,9,0}; compTotal (arr); total = arr[1] + arr[3]; cout << "The total of element 2 and 4 is " <« total <« endl; 12 13 14 15 16 return 0; 17 Error in line 13: The indices of the array do not indicate the value in the element 2 and element 4. No Error. Error in line 4: The return datatype by the function compTotal(..) should be integer. Error in line 11: The declaration of a variable and an array should not be combined in one statement.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 1PP: (Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard...
icon
Related questions
Question

Need this answer. Thank you

The program displays the sum of element 2 and element 4 of an array. Identify if
it contains any error. If yes, locate and state the error.
#include <iostream>
using namespace std;
3
void compTotal(int a[]){
for (int i = 0; i < 10; i++) {
a[i] = a[i] * 2;
4
8
9
int main () {
int total = 0, arr[10] = (1, 2,3,4,5,6,7,8,9,0};
compTotal (arr);
total = arr[1] + arr[3];
cout << "The total of element 2 and 4 is " <« total « endl;
10
11
13
14
15
16
return 0;
17
Error in line 13: The indices of the array do not indicate the value in the element 2 and
element 4.
No Error.
Error in line 4: The return datatype by the function compTotal(..) should be integer.
Error in line 11: The declaration of a variable and an array should not be combined in
one statement.
1234
Transcribed Image Text:The program displays the sum of element 2 and element 4 of an array. Identify if it contains any error. If yes, locate and state the error. #include <iostream> using namespace std; 3 void compTotal(int a[]){ for (int i = 0; i < 10; i++) { a[i] = a[i] * 2; 4 8 9 int main () { int total = 0, arr[10] = (1, 2,3,4,5,6,7,8,9,0}; compTotal (arr); total = arr[1] + arr[3]; cout << "The total of element 2 and 4 is " <« total « endl; 10 11 13 14 15 16 return 0; 17 Error in line 13: The indices of the array do not indicate the value in the element 2 and element 4. No Error. Error in line 4: The return datatype by the function compTotal(..) should be integer. Error in line 11: The declaration of a variable and an array should not be combined in one statement. 1234
Expert Solution
steps

Step by step

Solved in 4 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
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr