Why am i getting a syntax error by my cout statement? it\'s saying that cout was
ID: 3583242 • Letter: W
Question
Why am i getting a syntax error by my cout statement? it's saying that cout was not declared in the scope
//Function definition
void remove(int arrayList[], int& size, int removeItem)
{
//Variable declaration
int i,j;
//Repeat the loop until the size of the array
for (i=0; i //Assign remove item to array
if(arrayList[i]==removeItem)
//Check the condition
if(i==size-1)
{
//Decrease the items
size--;
return;
}
else
{
//Repeat the loop until the size of the array
for(j=i; j arrayList[j]=arrayList[j+1];
size--;
return;
}
cout<<"The item"<
Explanation / Answer
there is error in for loop
void remove(int arrayList[], int& size, int removeItem)
{
//Variable declaration
int i, j;
//Repeat the loop until the size of the array
for (i = 0; i < size; i++) //Assign remove item to array
if (arrayList[i] == removeItem){
//Repeat the loop until the size of the array
for (j = i; j < size; j++)
arrayList[j] = arrayList[j + 1];
size--;
}
return;
}
Sample code to test:
#include <iostream>
using namespace std;
void remove(int arrayList[], int& size, int removeItem)
{
//Variable declaration
int i, j;
//Repeat the loop until the size of the array
for (i = 0; i < size; i++) //Assign remove item to array
if (arrayList[i] == removeItem){
//Repeat the loop until the size of the array
for (j = i; j < size; j++)
arrayList[j] = arrayList[j + 1];
size--;
}
return;
}
int main()
{
int arr[] = { 1, 2, 3, 45, 6, 7, 8 };
int SIZE = 7;
remove(arr, SIZE, 6);
for (int j = 0; j < SIZE ; j++) {
cout << arr[j] << " ";
}
return 0;
}
Output: (remove the 6 in array)
1 2 3 45 7 8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.