Thread: Array question

  1. #1
    Registered User
    Join Date
    Oct 2005

    Question Array question

    Hello there-

    I'm drawing a blank here with this problem: create an array of grades based on user input, add up the scores and return a letter grade. Anyhoo...what I can't seem to figure out is what the best way to create this array. I would like the user to be able to add each score one at a time ("87", "78", "100", "97"...) until the Enter key is pressed.

    Any help is extremely appreciated!!!

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    well, here is simple algorithm
    integer scorearray;
          prompt user to enter score
          get val
          scoresarray <- val
    }while val not equal to '\n';
    find the sum of all the scoresarray
    grade <-- findgrade(send the sum);
    output grade
    u will have to think about the findgrade function

    hope this help you


  3. #3
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Sydney, Australia
    Presumably it's an assignment. Does the assignment mention a maximum number? In which case, create an array of N grades, then have it not allow the user enter more than N values.

    If it truly has to be of arbitrary length, you could use a pointer and realloc, or ask the user how many grades they will enter, then malloc to that amount.

    Finally, you could use a linked list or something, but that's somewhat overkill for this.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Thank you both.
    This is what I had in the meantime - I think I'm on the right track.

    	printf	("\nPlease enter assignments scores, one at a time. Press Enter key when done:");
    	scanf	(  "%i", aScore);
    	}	while ('\n'!=getchar());

  5. #5
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    int grades[100]={0}, i=0;
    while(scanf("%d",&grades[i]) == 1 && i++<100);
    could be one solution...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM