![]() |
read integers from file into an array
having a problem with a program not sure what I'm doing wrong. I to write this program that
inputs integer data from a file into an array of size 100. We have to create a variable to keep track of how many numbers were read into the array, then determine where in the array the highest and lowest value reside. here's what I have so far... :
|
Re: read integers from file into an array
line 11:
myArray is not an int array. It needs to be declared like this: :
int myArray[100] = {0};line 23: do not make the assumption that the file contains 100 integers -- maybe it only contains 10, maybe it contains a million. The idea is to read the file until end-of-file is reached or your array is filled up, whichever somes forst. So the way to code that loop is like this: :
while( inFile >> myArray[i]) max. To find the max value, just keep track of the maximum value as they are being read from the file :
int max = -1000; |
Re: read integers from file into an array
what about the min value? do i use the else if statement?
|
Re: read integers from file into an array
:
|
Re: read integers from file into an array
>>do i use the else if statement
No, just use another variable and statement like I did for the max value. I wouldn't use the else statement because maybe the current value just read affects both min and max. :
int max = 0;And you forgot to add code tags |
Re: read integers from file into an array
I'm sorry about the code tags...I'm a newbie, still learning
|
Re: read integers from file into an array
I'm sorry.....I am so lost....do I need lines 10-13? and where would I place the
:
int max = [-1000];also what is the code tags? |
Re: read integers from file into an array
>>do I need lines 10-13?
yes. But you need to change line 11 as I said previously. >>where would I place this replace lines 23 and 24 with the lines that were in my most post #5 >>also what is the code tags? Read your PM that I sent you. It shows you how to do it. |
Re: read integers from file into an array
didn't get the PM?
|
Re: read integers from file into an array
I treid using your post #2 about line 11 and I keep getting a error saying invalid initializer...
|
| All times are GMT -5. The time now is 3:44 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC