Good Morning DaniWeb users,
This will be the first time I use your forum to try and solve a problem.
I'm an non-traditional student and live in Michigan. For those curious about where that is located; look a world map (for our international friends) and look for the United States, my state looks like a hand.
I am in my first semester of C++ programming and my focus for my bachelors will be software engineering.
I have a program that I am having trouble, which, I am hoping is trivial to some of the more experienced memebers.
I have to declare a 500 element array. Get an unknown number of integers from a text file.
I have no trouble getting data from a text file when I know the amount of data that will be going into the array. However, when it is unknown I get some crazy results.
I have attempted to research things online without any luck.
Here is what I have so far, any input would be greatly appreciated.
Kindest regards,
Joseph
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
const int SIZE = 500; //Size declaration of array
int scores[SIZE]; //Array declaration
int count; //Loop counter variable
ifstream inputFile; //Input file stream object
inputFile.open("myTestData.txt"); //Opening the file
if(!inputFile) cout << "Problems with file!\n";
//Read numbers from file into the array
for(count = 0; count < SIZE && inputFile >> scores[SIZE]; count++)
inputFile >> scores[count];
//Close the file
inputFile.close();
//Display the numbers in the array
cout << "The numbers are: \n";
for(count = 0; count < SIZE; count++)
{
cout << scores[count] << "";
cout << endl;
}
system("pause");
return 0;
}