Array Txt File Project

Hello,
I have a project due in Computer science in which I have nearly finished, but I am having trouble trying to configure the code to output correctly. Any help is much appreciated.
1. Create a new project in Code Blocks for a program that will:
Read in a file of sales dollar amounts (doubles) and store them in an array.
The maximum number of amounts that the file could
contain is 20, but it could have less, and
zero (0.00) marks the end of the valid data.

Your program should read in the data and :
Determine the smallest amount in the file.
Determine the largest amount in the file
Sort the amounts from lowest to highest.

2. The program will output to a file the following items:
"The number of sales amounts in the file is "
"The lowest sales amount is "
"The highest sales amount is "
"Here is the list of amounts sorted from lowest to highest:"

3. Create and use a test file with the following values in the order that they appear below:
29.95, 3.55, 34.70, 12.34, 2.67, 33.89, 24.99, 18.45, 4.99, 9.95, 0.00

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
127


#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

void FillArray(double a[], int arraySize, int number_used);
void Sort(double a[], int number_used);
int IndexOfSmallest(const double a[], int start_index, int number_used);
void swap_values(double& v1, double& v2);
void Output();

ifstream InStream;
ofstream OutStream;

int number_used, size, values, i=0;
double Arrow, Sorted, Small, Large, Array[20];

int main()

{
    int arraySize = 20;

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

    OutStream.open("fileStauffer.txt");
    if (OutStream.fail())
    {
    cout << "Input file opening failed.\n";
    exit(1);
    }

for (number_used=0;number_used < 5;i++)
cout<<Array[number_used]<<endl;

    FillArray(Array, arraySize, number_used);
    Sort(Array, number_used);
    Output();

 InStream.close( ); // Close Files Outta Loop
 OutStream.close( );

 cout << "The program has completed successfully.\n";
 return 0;

 } // End Main

 //Functions
 void FillArray(double a[], int arraySize, int number_used)
 {
  int Next, index = 0;
  InStream >> Next;
  while ((Next >= 0) && (index < arraySize))
  {
  a[index] = Next;
  index++;
  InStream >> Next;
  }
  number_used = index;
 }

 void Sort(double a[], int number_used)
 {
  int IndexNextSmallest;

    for (int index = 0; index < number_used - 1; index++)
    {
        IndexNextSmallest = IndexOfSmallest(a, index, number_used);
        swap_values(a[index], a[IndexNextSmallest]);
    }
 }

int IndexOfSmallest (const double a[], int start_index, int number_used)
{
 int index_of_min = start_index;

 int min = a[start_index];

 for (int index = start_index + 1; index < number_used; index++)
    if (a[index] < min)
   {
    min = a[index];
    index_of_min = index;
   }

   return index_of_min;
}

void swap_values(double& v1, double& v2)
{
    double temp;

    temp = v1;

    v1 = v2;

    v2 = temp;
}

void Output() // Output Section

{
 OutStream.setf(ios::fixed);

 OutStream.setf(ios::showpoint);

 OutStream.precision(2);

 OutStream << "The Number Of Sales Amounts In The File Is " << number_used << endl;

 OutStream << "The Lowest Sales Amount Is $ " << Array[0] << endl;

 OutStream << "The Highest Sales Amount Is $" << Array[number_used - 1] << endl;

 OutStream << "List Of Sorted Numbers " << endl << endl;
 for (int i = 0;i < number_used; i++)
    OutStream << Array[i]<<endl;

}
Last edited on
what exactly is the problem?
Topic archived. No new replies allowed.