The program's purpose is to fill two arrays from data in a file, the first column is department number, and the second is boxes sold. There should be a max of 15 departments, variables departmentNumber and boxesSold should receive data from file before filling array
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
int departmentNumber = 0, boxesSold = 0;
ifstream inputFile("boxes.txt");
const int SIZE = 15;
int departmentArray[SIZE];
int boxesArray[SIZE];
int count = 0;
while (count < SIZE && inputFile);
{
inputFile >> departmentNumber;
inputFile >> boxesSold;
for (int index = 0; index < count; index++)
{
if (departmentArray[index]== departmentNumber)
{
boxesArray[index] = boxesArray[index] + boxesSold;
}
else
{
departmentArray[index] = departmentNumber;
boxesArray[index] = boxesSold;
count++;
}
}
inputFile.close();
}
//display numbers
for (int i = 0; i < count; i++)
{
cout << departmentArray[i] << " ";
cout << boxesArray[i];
cout << endl;
}
system("pause");
}
current output is blank. my for loop searches array to see if departmentNumber already exist, my while loop continues to accept data from file, and the last for loop displays number. Been stuck on this for too long.
int count = 0;
while (count < SIZE && inputFile)
{
inputFile >> departmentNumber;
inputFile >> boxesSold;
for (int index = 0; index < count; index++)
{
if (departmentArray[index] == departmentNumber)
{
boxesArray[index] = boxesArray[index] + boxesSold;
}
else
{
departmentArray[count] = departmentNumber;
boxesArray[count] = boxesSold;
}
}
boxesArray[count] = boxesSold;
count++;
}
inputFile.close();
i updated the code and the following output is given, my guess is the for loop, that or index/count is not declared properly,
-858993460 23
410 17
410 16
120 14
150 32
300 27
410 11
410 10
120 8
150 16
120 2
300 4
410 5
520 6
390 7
Press any key to continue . . .