Grades

This is a discussion on Grades within the C Programming forums, part of the General Programming Boards category; Im trying to write a program that will read 10 grades from the user and store them in an array. ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    5

    Grades

    Im trying to write a program that will read 10 grades from the user and store them in an array. Then call a function, that takes the array as a parameter and then display all the grades below 70 and all the grades above 96. This is what I have so far.......

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    void analyze(const int b[]);
    int main(int argc, char *argv[])
    {
     	int grades[10];
     	int x; //counter
     	
     	printf("Enter 10 grades:\n");
     	
     	for(x = 0; x < 10; x++){
    		  scanf("%d", &grades[x]);
    		  }
    
    	analyze(grades);	  
    
      system("PAUSE");	
      return 0;
    }
    
    void analyze(const int b[])
    {
     	 int j; //counter
     	 
     	 for(j=0; j<10; j++){
    	 		  if(b[j] < 70)
      		  	  
    	  }
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Is there a problem?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,422
    if you are certain that there are always 10 grades then declare a const int
    you just need to complete the if statement in your analyse function with an output line and add an else if say for the other condition, but like the man said...do you have a problem at all?

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    Yea, I want to display the grades that are lower that 70 and greater than or equal to 96. I think i got most of the code here, I just can't seem to figure out the last few parts in the function and return it to the main..

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,422
    if(b[j] < 70)

    you already started that bit

  6. #6
    Registered User
    Join Date
    Jan 2010
    Posts
    5
    so I would just finish the if statement as follows:

    Code:
    if(b[j] < 70) || b[j] >= 96)
    this is where i get stuck.. would I use a return statement and return it to the main and use printf there or after the if statement in the function? I dont know if that makes sense, sorry Im bad at explaining lol

  7. #7
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,422
    you dont need to return anything, the array is passed by reference anyway, and besides your function is declared void, so yes i would just print out each value in the function whenever one of the two valid conditions is met, with an appropriate message in each case, its the most straightforward way anyhow, why overcomplicate

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by ksample23 View Post
    this is where i get stuck.. would I use a return statement and return it to the main and use printf there or after the if statement in the function? I dont know if that makes sense, sorry Im bad at explaining lol
    I would print them out in the function, with that if statement inside the for loop.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-19-2009, 03:22 AM
  2. Replies: 2
    Last Post: 02-08-2009, 08:26 PM
  3. bare bones grades program
    By stormy in forum C Programming
    Replies: 6
    Last Post: 09-13-2005, 04:06 PM
  4. Grades program has me lost
    By adrea in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2002, 07:35 PM
  5. Replies: 13
    Last Post: 08-15-2002, 09:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21