really need help on some coding

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bubblegum1001
    New Member
    • Jan 2014
    • 2

    really need help on some coding

    right so i got given this Using a for loop to input and output array values
    */

    Code:
    #include <stdio.h>
    
    
    int main(void)
    {
    	/* 	Declare an array of integers */
    	int Grades[5];
    	int nCount;
    
    	/* Populate the array */
    	for(nCount = 0; nCount < 5; nCount++)
    	{
    		printf("\nPlease enter a value for array element %d : ",nCount);
    		scanf("%d",&Grades[nCount]);
    	}
    	
    	printf("\n\n");		/* Just a couple of lines to add a gap */
    	
    	/* Display the array */
    	for(nCount = 0; nCount < 5; nCount++)	/* Note that reusing nCount */
    	{
    		printf("Array element %d has the value %d\n", nCount, Grades[nCount]);
    	}
    
    	return 0;
    }
    what i have to do is Extend the code such that it also counts all entered values in the range -10 to -120 inclusive.
    The code should now record the maximum and minimum values within each of the three specified ranges.
    what do i do ?
    Last edited by Rabbit; Jan 24 '14, 06:50 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Just define variables outside the loop that populates the array. You will need one variable for the count in the -10 to -120 range. You will need others for the min/max counts. Initialize all these counts to 0.

    Add code to the populate array loop to test the value of Grades[nCount]. If Grades[nCount] > min, change min to Grades{nCount] and add 1 to the min counter. If Grades[nCount] > max, change max to Grades[nCount] and add 1 to the max counter.

    Remember in testing ranges you use (Grades[nCount] <= -10) && (Grades[nCount] >= -120). If this expression is true you are in the range -10 to -120. This is where you increment your count of values in the range.

    Give it try and post again if you are still stuck.

    Comment

    • bubblegum1001
      New Member
      • Jan 2014
      • 2

      #3
      i know this is going to sound really really dumb i actually just started learning programming and havent got the jist of it yet would it be possible if you could kinda show me how you would do the code yourself i mean actually write it i just want to know :/

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Help with programming is one thing and help with C or C++ is something else. How to program is a subject by itself. Once you know why you use loops and conditional statements, then you can apply that knowledge to this problem.

        And you don't sound really dumb. You are just a beginner and every expert went through the same painful learning process. Having me write your code will not help you learn. In fact, it will make your learning process harder because you might not be able to understand what I coded.

        Just take a few minutes an learn how to write logical comparisons using an if/else statement. That's all you will need to solve this problem.

        Post again when you have some code written.

        Comment

        Working...