I'm making code that read a text file the display the number then sort them from least to greatest I'm using C++ to code this. I'm running into two problems fist I'm getting two numbers that are not in the least a big negative number and 622 with is not in the list. I think this is because of a null retune to an array
#include<iostream>
#include<cmath>
#include <iomanip>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
const string INFILENAME = "100Numbers.txt"; //this find the name in the program foulder
ifstream inFile;
inFile.open(INFILENAME.c_str());//this open the file
const int NUMBER = 100;
int OneHundredNumber[NUMBER];
int NewOneHundredNumbe[NUMBER];
int Size = 0;
int FindSize;
int found = 0;
if (inFile.is_open())
{
while (!inFile.eof()) { //in the File when it hits -1 i what it to not input -1 and stop it
inFile >> OneHundredNumber[Size];//this is put the text in to the first arry
Size++;
}
printArray(NewOneHundredNumbe, Size, "");//note i this this is not need
loopfortheLoop(Size, NewOneHundredNumbe, OneHundredNumber, "The contents of the array are: ");
sort(OneHundredNumber, OneHundredNumber + Size);
loopfortheLoop(Size, NewOneHundredNumbe, OneHundredNumber, "The array has been sorted.");
for (int i = 0; i < Size; i++)
{
if (OneHundredNumber[i] == 234) {
found++;
}
}
cout << endl << "The number ""234"", was found " << found << " times.";
inFile.close(); // CLose input file
}
else { //Error message
cerr << "Can't find input file " << INFILENAME << endl << "Pleace add it to the Progeran Files or cheack if the name of the text file is 100Numbers.txt";
}
return 0;
}
100Numbers.txt
137 354 328 263 120 36 124 138 175 365 180 170 179 144 45 379 97 31 357 274 142 314 3 327 321 137 122 331 308 366 352 71 363 14 85 266 287 80 91 370 117 374 57 204 224 148 268 280 292 363 399 388 325 234 230 331 89 390 212 55 297 622 151 266 272 63 331 21 250 141 154 15 61 234 23 143 99 389 196 29 361 180 288 47 62 50 347 180 234 334 130 230 184 214 177 154 129 391 234 -1