Hello my name is roman I have this project to do that involves the following:
I need to take a text document full of numbers and output the lowest of those numbers and the highest of those numbers but they first have to be put into an array then outputted... I have all the code for locating and outputting the text file...I also have outputted the highest and lowest values using if statements but could someone share how I can put them into an array?
This is all the code that i have so far with no errors:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream indata;
int num=0, high=0, low=10000, enter;
char chars[50];
char newline = '\n';
indata.open("distance.txt");
if(!indata) {
cerr << "Error: file could not be opened" << endl;
exit(1);
}
indata >> num;
cout<<"Type read and press enter to read info for 'distance.txt'"<<endl;//need to clarify if and else statements
cin>>enter;
while (enter = !indata.eof() )
{
cout << " " << num << endl;
indata >> num;
if(high<num)
{
high=num;
}
if(low>num)
{
low=num;
}
}
indata.close();
cout << "End-of-distance.txt....." << endl;
cout<<"The high value is "<<high<<endl;
cout<<"The low value is "<<low<<endl;
return 0;
}