Array

Range from lowest to highest

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

35 Replies - 3823 Views - Last Post: 18 February 2010 - 07:21 PM Rate Topic: -----

#31 sf18   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 148
  • Joined: 29-November 09

Re: Array

Posted 18 February 2010 - 06:02 PM

@n8wxs
Yea I also tried that see:
	for( col = 0; col < QUIZZES; col++ ){
			for( row = 0; row < STUDENTS; row++ ){
				if(qScores[row][col] < low){
					low = qScores[row][col];
				}
				if(qScores[row][col] > high){
					high = qScores[row][col];
				}
				// may not be in the right place?? Is it correctly reintialized?
				high = 0;
				low = 100;
			}

		printf("Quiz %i: %i - %i\n", col, low, high); 
	}
	


Output:

Quiz 0: 100 - 0 <-- Doesnt go through column at all...
Quiz 1: 100 - 0
Quiz 2: 100 - 0
Quiz 3: 100 - 0
Quiz 4: 100 - 0
Quiz 5: 100 - 0
Quiz 6: 100 - 0
Press any key to continue . . .
Was This Post Helpful? 0
  • +
  • -

#32 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Array

Posted 18 February 2010 - 06:08 PM

reread my post #17
Was This Post Helpful? 0
  • +
  • -

#33 sf18   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 148
  • Joined: 29-November 09

Re: Array

Posted 18 February 2010 - 06:28 PM

Attempt 1:
	for( col = 0; col < QUIZZES; col++ ){
			for( row = 0; row < STUDENTS; row++ ){
				high = qScores[row][col];
				low = qScores[row][col];
				
			}
				if(qScores[row][col] < low){
					high = 0;
				}
				if(qScores[row][col] > high){
					low = 100;
				}


		printf("Quiz %i: %i - %i\n", col, low, high); 
	}


Output:

Range
Quiz 0: 65 - 0
Quiz 1: 100 - 86
Quiz 2: 100 - 88
Quiz 3: 100 - 0
Quiz 4: 100 - 51
Quiz 5: 100 - 92
Quiz 6: 75 - 0
Press any key to continue . . .

Attempt 2:
for( col = 0; col < QUIZZES; col++ ){
			for( row = 0; row < STUDENTS; row++ ){
				high = 0;
				low = 100;
				
			}

				if(qScores[row][col] < low){
					high = qScores[row][col];
				}
				if(qScores[row][col] > high){
					low = qScores[row][col];
				}	


		printf("Quiz %i: %i - %i\n", col, low, high); 
	}

Output was a bunch of junk numbers. And then I tried the if-statment completly out of the for loop didnt work either. :(

Am I intializing the 'high' and 'low' correctly? Or are my if-statments still in the wwrong position?
Was This Post Helpful? 0
  • +
  • -

#34 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Array

Posted 18 February 2010 - 06:56 PM

Yes, your if() statements are in the wrong place.

Go back to the for() loops you had in post #31

Put in init statements between the two for() statements.
Was This Post Helpful? 0
  • +
  • -

#35 sf18   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 148
  • Joined: 29-November 09

Re: Array

Posted 18 February 2010 - 07:11 PM

I can't try it on my compiler right away because I'm using my Mac. But I should implement like this:
]for( col = 0; col < QUIZZES; col++ ){
                                 high = 0; // initialize here?
                                low = 100;                     
                        for( row = 0; row < STUDENTS; row++ ){
                                if(qScores[row][col] < low){
                                        low = qScores[row][col];
                                }
                                if(qScores[row][col] > high){
                                        high = qScores[row][col];
                                }
                                
                              
                        }

                printf("Quiz %i: %i - %i\n", col, low, high); 
        }

} 

Sorry to keep bothering :sad3:
Was This Post Helpful? 0
  • +
  • -

#36 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Array

Posted 18 February 2010 - 07:21 PM

Yes


:)
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3