Program Terminating unexpectedly

Hello Guys

After compiling my program on running its just terminating unexpectedly please advise what i should do ? thank you in advance..

regard

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  
#include <iostream>
#include <cassert>

// Question M
//Write a program that asks a user to enter the size of a dynamic array that stores scores obtained by students.
// Create the dynamic array and a loop that allows the user to enter a score into each array element.
// Loop through the array, find the maximum score and output it.
// Delete the memory allocated to your dynamic array before exiting your program.

using namespace std;

int main()
{
    int arraySize;
    int *arrayName;
    arrayName = new int [arraySize] ;
    int studentScores = 0 , maxScore = 0 ;
    int  i;

    cout << "Enter the size of the array" << endl;
    cin>>arraySize;
    //assert ( arraySize > 0 );                                 // checking for a number greater than zero
    cout<<" You entered and array of size "<<arraySize<<endl;    // feedback
    cout<<" Enter the scores for each student "<<endl;           // requesting input for  student scores
    cin>> studentScores;
    while ( studentScores >= 0 )

        {
                 for ( i = 0 ; i <= arraySize ; i++)

                arrayName[arraySize] = studentScores;

                cout<< " Student scores are as follows ;  "<<arrayName[i];

                if (arrayName[i] > maxScore)

                    {
                        maxScore = arrayName[i];
                        cout<< " Maximum student score is "<<maxScore;

                    }

        }

     delete [] arrayName;
    return 0;
}

You are creating the array with a size of arraySize before getting a value for arraySize. So the error you should get is arraySize not initialized. What you need to do is create the array after getting a value for arraySize.
Thanks Joe its running now after initialising it.
Topic archived. No new replies allowed.