Join 136,104 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,693 people online right now. Registration is fast and FREE... Join Now!
depends what you want to do. are there errors in the code? is the output not what you expect/want? please be a little more specific. the code looks like it should run fine as is, so where so you want to go from here?
and please use the code tags for posting code - take a look at the gray text on the background of the post/reply text box. and just so you know, you can also edit your previous post to add the tags.
depends what you want to do. are there errors in the code? is the output not what you expect/want? please be a little more specific. the code looks like it should run fine as is, so where so you want to go from here?
and please use the code tags for posting code - take a look at the gray text on the background of the post/reply text box. and just so you know, you can also edit your previous post to add the tags.
-jjh
The program runs O'K, but i have to store the result in 2D arrays and i'm really lost
for a statically allocated (compile-time) 2d array, the syntax isn't too tough. you just need to include another [] in your declaration and accessing.
for instance, if you want a 2D array with the high temps in column 0 and the lows in column 1, you would declare your variable index as int index[MONTH][2]. then you could input the values for the highs into index[i][0], and the lows into index[i][1].
and passing to a function would work in the same way. the function header would become:
for a statically allocated (compile-time) 2d array, the syntax isn't too tough. you just need to include another [] in your declaration and accessing.
for instance, if you want a 2D array with the high temps in column 0 and the lows in column 1, you would declare your variable index as int index[MONTH][2]. then you could input the values for the highs into index[i][0], and the lows into index[i][1].
and passing to a function would work in the same way. the function header would become:
you've got min, max, MinOne, MinTwo, MaxOne, and MaxTwo, and you're outputting stuff to both the screen and a file. exactly what is it not showing, and where is it not doing so?
maybe you should post a sample input and both the expected and actual output. then it would be a little easier to see where the problem is.
you probably aren't going to get the result you're looking for using outFile<<(max, min, ave)<<" . you need to use a separate insertion << for each variable: outFile<< max << " " << min << " " << ave<< " "
and usually printf and cout statements aren't mixed. there doesn't appear to be any reason why you can't just use cout << in this case.
you've got min, max, MinOne, MinTwo, MaxOne, and MaxTwo, and you're outputting stuff to both the screen and a file. exactly what is it not showing, and where is it not doing so?
maybe you should post a sample input and both the expected and actual output. then it would be a little easier to see where the problem is.
you probably aren't going to get the result you're looking for using outFile<<(max, min, ave)<<" . you need to use a separate insertion << for each variable: outFile<< max << " " << min << " " << ave<< " "
and usually printf and cout statements aren't mixed. there doesn't appear to be any reason why you can't just use cout << in this case.
hope that helps.
-jjh
I've got max, min, maxTwo and minTwo -thease are for high temp and for low temp .The algorithm for max and maxTwo is ok,but it displays a random temp. for min and minTwo and i can't realize whre my mistake is
I've got max, min, maxTwo and minTwo -thease are for high temp and for low temp .The algorithm for max and maxTwo is ok,but it displays a random temp. for min and minTwo and i can't realize whre my mistake is
oops. i saw the doubled up output (cout and file) for MaxTwo, and my brain did something weird there.
you probably don't want this:
CODE
if(index[MONTH][0]<max) min=index[MONTH][0];
since that will assign the current value that you're looking at to min any time that the current value is less than the max. which is not what a minimum is. you probably wanted
CODE
if(index[MONTH][0]<min) min=index[MONTH][0];
of course, this is probably going to cause you some problems, because you have intialized min and max to zero prior to your input loop. for doing an on-the-fly min/max search, you want to intialize them both to the first value entered. Do one input step outside of your loop, assign the value to the array, and also to your min and max values. then start the loop beginning with i=1.
I've got max, min, maxTwo and minTwo -thease are for high temp and for low temp .The algorithm for max and maxTwo is ok,but it displays a random temp. for min and minTwo and i can't realize whre my mistake is
I think there is something wrong with my "if"
CODE
for (int i = 0;i < temp_read;i++) { cout << "Enter the lowest temperature reading for month #" << i+1 << ": "; cin >> index[i][1];
Oopsss, we typed at the same time. I tried that example and it gave me a wrong negative answer... It gave me a real max temp. but the min was negative.
This post has been edited by dumb4o: 14 Oct, 2007 - 02:49 PM