Hello,
I'm working on some code for school and ran into an issue. The assignment is as follows:
"Write a program which reads the numbers.txt file (available in BlackBoard in the Week 2 folder). The file contains a series of numbers, each written on a separate line. The program will read the contents of the file into an array and then display the following information:
the lowest number in the array
the highest number in the array
the total of the numbers in the array
the average of the numbers in the array."
So I have my code to read the file which has 12 random numbers listed out, each on a new line, when I execute the code, it lists 12 numbers, the first is actually the last number in the list and the rest are 858993460 which is obviously not correct. How do I get it to read the rest of the numbers properly? Once I get that worked out I know how to get the rest of the parts of the assignment 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
|
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int ARRAY_SIZE = 12;
int numbers[ARRAY_SIZE];
int count = 0;
ifstream inputFile;
inputFile.open("C:\\users\\rocke\\desktop\\numbers.txt");
while (count < ARRAY_SIZE && inputFile >> numbers[count]);
count++;
inputFile.close();
cout << "The numbers are: " << endl;
for (count = 0; count < ARRAY_SIZE; count++)
cout << numbers[count] << " " << endl;
return 0;
}
|