Hi,
Sorry if this question seems really stupid. For this code I'm reading in a text file containing numbers and retrieving the minimum and maximum numbers. (Each number is on a separate line in random order). I can work out the maximum number but can't work out the minimum number correctly.
Any help would be appreciated.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]){
char buffer[255];
ifstream input(argv[1]);
double num[100];
int i = 0;
double max = num[0];
double min;
while(!input.eof()){
input.getline(buffer, 100);
num = atof(buffer);
line++;
i++;
}
for (int j = 0; j<line; j++) {
if (num[j] > max) {
max = num[j];
}
}
//this loop doesnt seem to work
for (int k = 1; k<line; k++) {
if (max > num[k]) {
min = num[k];
}
}
}
Sorry if this question seems really stupid. For this code I'm reading in a text file containing numbers and retrieving the minimum and maximum numbers. (Each number is on a separate line in random order). I can work out the maximum number but can't work out the minimum number correctly.
Any help would be appreciated.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]){
char buffer[255];
ifstream input(argv[1]);
double num[100];
int i = 0;
double max = num[0];
double min;
while(!input.eof()){
input.getline(buffer, 100);
num = atof(buffer);
line++;
i++;
}
for (int j = 0; j<line; j++) {
if (num[j] > max) {
max = num[j];
}
}
//this loop doesnt seem to work
for (int k = 1; k<line; k++) {
if (max > num[k]) {
min = num[k];
}
}
}