I'm trying to create an array where the user goes out-of-bounds and executes an error message. I wanted to access each element of the array and then once I go past the last element it will execute the message. This is what I have so far
using namespace std;
class safeArray{ //line1
public: int array[]; //line2
};
void outofBounds(int array[],int sizeofArray); //line3
int main() { //line4
int array [3]={2,4,6}; //line5
outofBounds (int array[],int sizeofArray){ //line6
for (int i=0;i<sizeofArray;i++){ //line7
i++ //line8
}
if (int i=0;i>sizeofArray){ //line9
cout<<"safeArray array (" <<list[0]<<","<<array[3]<<endl; //line10
}
}
return 0;}
I'm getting confused because line 6 is showing up as an error? It's asking for a ( in front of sizeofArray. Why is that?
Edit:
Made some edits. Still getting an error.
#include <iostream>
using namespace std;
class safeArray{
public:
void outofBounds(int,int);
int yourArray[3];
int i;
};
void outofBounds(int,int);
int yourArray[3];
int i;
int main() {
void outofBounds(int,int);
int yourArray[3]; //Error: Unused Variable 'yourArray'
return 0;
};
void outofBounds(int yourArray[],int sizeofArray) {
for (i=0;i<sizeofArray;i++){
cout<<"Please enter integer";
cin >>yourArray[i];
yourArray[i]++;
for (i=0;i>sizeofArray;){
cout<<"safeArray yourArray ("<<yourArray[0]<<","<<yourArray[3]<<")"<<endl;
}
}
}