Hi im starting to learn c++ and im having a little issue that im not capable of correct yet...
the program ask the user to imput the size of an array then the program create it at that size, fill it with random integers and output the array into the screen.
Here is the code. it compiles well but at run time appears after imput an annoying error box when imputs are greater than > 5;
here is my code
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void PrintArray(int* array, int size);
void RandomArrayFill(int* array, int size);
void RandomArrayFill(int* array, int size)
{
int i=0;
for(i=0;i<size+1;i++)
{
array[i]= rand() % 101;
}
}
void PrintArray(int* array, int size)
{
int i=0;
for(i=0;i<size+1;i++)
{
if(i==size)
{
cout <<array[i] << "}" << endl << endl;
break;
}
cout << array[i] << ", " ;
}
}
void main()
{
int numero=0;
int* bobby=0;
srand( time(0) );
do
{
cout << "Enter the size of an array to create: ";
cin >> numero;
bobby = new int(numero);
RandomArrayFill(bobby, numero);
cout << endl << endl << "Creating array and filling it with random numbers...";
cout << "Array = {";
PrintArray(bobby, numero);
//delete [] bobby;
//bobby=0;
}
while(numero!=0);
cout << "NULL Array" << endl;
}
hope you could help me out thx in advance