0

The purpose of the program is to store values in array from a file salesData.txt which contains the values as shown below. The program should stop at the sentinel value that is 0.0. The code is not working as expected. . This is the question.

Create a program that reads in a series of sales dollar amounts from a file, stores the amounts in an array, processes the array, and outputs to a file and the console the number of sales amounts, the lowest amount, the highest amount, and a complete list of the amounts in order from lowest to highest. Sample output shown on the next page.
The maximum number of amounts in the file is 20, but it could have less. The program must keep track of the number of amounts read in from the file, and stop at the sentinel.
Required functions: (1) opening the files and file failure conditions, (2) reading the input and storing the values, (3) sorting the array, (4) writing and displaying the output.
Create an input file named “salesAmounts.txt” with the following values in the order that they appear below vertically in the file. Zero marks the end of the data set and is not one of the amounts. The file location must be the project folder.
Sample data:

29.95 3.55 34.70 12.34 2.67 33.89 24.99 18.45 4.99 9.95 0.00
This is my program so far

#include<iostream>
#include<fstream>
void bubble_sort(int arr[] , int length)
{

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

int main()
{
    const int ARRAY_SIZE=10;
    int numbers[ARRAY_SIZE];
    int count=0;
    ifstream inputFile;
     inputFile.open("salesData.txt");
    while (count ARRAY_SIZE && inputFile>> numbers[count])
     count++;
      inputFile.close();
    return 0;
}
void fill_array(double salesValues[], int arraySize,int &filledSlots)
{
double nextValue;
int index=0;
in_stream>> nextValue;
while((nextValue>0)&&(index<arraySize))
{
salesValues[index]=nextValue;
index++
in_stream>>nextValue;
}
filledSlots=index;

void output_sales_data(double salesValues[],int filledSlots)
{
intarraySlot=0;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"The number of sales amount is :"<< filledSlots<<endl;
cout<<"The lowest amount is :$"<<salesValues[0]<<endl;

cout<<"The highest is $"<<salesValues[filledSlots-1]<<endl;
cout<<"The list of values sorted from lowest to highest:"<<endl;

while(arraySlot< filledSlots)
 {
 cout<<"$"<<salesValues[arraySlot]<<endl;
 arraySlot++;
}
   }
2
Contributors
1
Reply
25
Views
9 Months
Discussion Span
Last Post by rproffitt
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.