C++NumbersInt.txt is not really a valid file name. Yes you can create it in windows, but DOS will have a fit. I would remove the ++ for a command line program.
Ok so you don't believe me... type c:\temp> copy con C++NumbersInt.txt
It doesn't work
you can cheat and type c:\temp> copy con "C++NumbersInt.txt" and that works, but it shows you by doing that it's a special or long or non-dos file name. It will be easier just to not use special chars.
The program will only look in the current directory, or the directory where it expects it to be. If you want it to look somewhere else, you have to tell it.
inputFile.open("c:\\Temp\\numbers.txt");
You are writing command line files, I suggest you run the code from the command line. DOS Prompt.... Then you can get rid of that
system ("PAUSE");
which most programmers don't like. If you have to pause a screen, try using getch(); instead. You will have to use
#include <conio.h>
use code tags when you post your code so I can tell you on line XYZ you need to change.
inputFile.close();
There are many ways to do the next part, the easiest is
Define your vars
1 2 3
|
int LowestNum=0;
int LargestNum=0;
int SumNum=0;
|
Then put in a if statement like
1 2 3 4 5 6 7 8 9 10
|
if (count == 0)
{LowestNum=numbers[count];LargestNum=numbers[count];}
else
if (numbers[count] < LowestNum)
{LowestNum=numbers[count];}
else
if (numbers[count] > LargestNum)
{LargestNum=numbers[count];}
SumNum=SumNum+numbers[count];
count++;
|
show the output
1 2 3 4
|
cout << "Numbers in file: " << count << endl;
cout << "Lowest Number : "<< LowestNum << endl;
cout << "Largest Numbers: "<< LargestNum << endl;
cout << "Average : "<< SumNum/count << endl;
|
If something gets messed up, put in a cout in each If statement showing what the values are. You may at times have to put them in when you read them to make sure they don't get changed somewhere else.