Need help!

I can't understand why this program isn't running. Getting a ".exe has stopped working."

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 #include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

void open_files ();
void fill_array (double salesArray[], int ARRAY_SIZE, int& slotsPopulated);
void sort_array (double salesArray[], int slotsPopulated);
void display_sales_data (double salesArray[], int slotsPopulated);
void output_sales_data (double salesArray[], int slotsPopulated);

ifstream in_stream;
ofstream out_stream;

  const int ARRAY_SIZE = 20;

int main ()
{
    int ARRAY_SIZE, slotsPopulated;
    double salesArray [ARRAY_SIZE];

    open_files ();
    fill_array (salesArray, ARRAY_SIZE, slotsPopulated);
    sort_array (salesArray, slotsPopulated);
    display_sales_data (salesArray, slotsPopulated);
    output_sales_data (salesArray, slotsPopulated);

    in_stream.close();
    out_stream.close();
    cout << "Successful Completion";

return 0;
}

void open_files ()
{
    in_stream.open("salesAmounts.txt");
    if (in_stream.fail())
    {
        cout << "Input file opening failed.\n";
        exit(1);
    }

    out_stream.open("schreiberAmounts.txt");
    if (out_stream.fail())
    {
        cout << "Output file opening failed.\n";
        exit(1);
    }
}

void fill_array (double salesArray[], int ARRAY_SIZE, int& slotsPopulated)
{
    int index = 0;

    double nextValue;

    in_stream >> nextValue;

    while ((nextValue > 0) && (index < ARRAY_SIZE))
    {
        salesArray [index] = nextValue;
        index ++;

        in_stream >> nextValue;

        salesArray[index] = 0;
        slotsPopulated = index;
    }
}

void sort_array (double salesArray[], int slotsPopulated)
{

    for (int i = slotsPopulated - 1; i > 0; i--)
        for (int j = 0; j < i; j++)
            if (salesArray[j] > salesArray[j+1])
            {
                double temp = salesArray[j+1];
                salesArray[j+1] = salesArray[j];
                salesArray[j] = temp;
            }

}

void display_sales_data (double salesArray[], int slotsPopulated)
{
    int arraySlot = 0;

   cout.setf(ios::fixed);
   cout.setf(ios::showpoint);
   cout.precision(2);

   cout<< "The number of sales amounts is: " << slotsPopulated << endl;
   cout<< "The lowest sales amount is: $" << salesArray [0] << endl;
   cout<< "The highest sales amount is : $" << salesArray[slotsPopulated -1] << endl;
   cout<< "List of the values sorted from lowest to highest: " << endl;

   while (arraySlot < (slotsPopulated))
    {
        cout<< " $"  << salesArray[arraySlot] << endl;
        arraySlot++;
    }
}

void output_sales_data (double salesArray[], int slotsPopulated)
{
    int arraySlot = 0;

    out_stream.setf(ios::fixed);
    out_stream.setf(ios::showpoint);
    out_stream.precision(2);

    out_stream << "The number of sales amounts is: " << slotsPopulated << endl;
    out_stream << "The lowest sales amount is: $" << salesArray [0] << endl;
    out_stream << "The highest sales amount is : $" << salesArray[slotsPopulated -1] << endl;
    out_stream << "List of the values sorted from lowest to highest: " << endl;

    while (arraySlot < (slotsPopulated))
    {
        out_stream << " $"  << salesArray[arraySlot] << endl;
        arraySlot++;
    }

}
closed account (48T7M4Gy)
Your program runs in the cpp shell.

Googling ".exe has stopped working" has some help but why not just try a reboot?
Topic archived. No new replies allowed.