Thread: Array Question

  1. #1
    Registered User
    Join Date
    Sep 2016
    Posts
    2

    Array Question

    Hi, I am a beginner on C trying to study by myself but hit a big wall on array.

    I don't get the part when I input 10 it only gives me only total of 40.
    How do I only get 40 when I asked the total of 10 players' amount of gold?

    I also tried to put 100 for players to receive gold, but the program shut down after inputting 1 player's gold. I guess that happened because it exceeded the amount of array that has been put there.

    The weird thing I also found is that when I put 50 players it gave me the total gold amount of 50 players and 70 as well.

    1. I need to know why it only produced 40 instead of 10 players' gold amount.
    2. why it produced exact amount of 50 players' total gold amount when the limit of array is 10.

    Thanks for the help in advance!
    Attached Images Attached Images Array Question-2016-09-05-2-png Array Question-2016-09-05-1-png 

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You're indexing your array with players, not playerCount.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2016
    Posts
    2
    Quote Originally Posted by Salem View Post
    You're indexing your array with players, not playerCount.
    So how should the code be looking?
    I am still confused after looking at the code again after waking up...

    NVM FIXED
    Last edited by RayCity; 09-05-2016 at 03:16 PM.

  4. #4
    Registered User
    Join Date
    Aug 2016
    Posts
    13
    Could you explain again what are you trying to do with this? And also what output were you expecting... sorry my english sucks and I'm a little bit lost lol

  5. #5
    Registered User
    Join Date
    Aug 2016
    Posts
    13
    Quote Originally Posted by RayCity View Post
    So how should the code be looking?
    I am still confused after looking at the code again after waking up...

    NVM FIXED
    Great!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-10-2016, 01:23 AM
  2. Array question
    By johnston in forum C Programming
    Replies: 23
    Last Post: 04-04-2012, 10:22 PM
  3. Replies: 12
    Last Post: 11-21-2010, 09:46 AM
  4. Array question
    By 182 in forum C++ Programming
    Replies: 12
    Last Post: 02-23-2006, 10:09 PM
  5. array question
    By Martijn in forum C++ Programming
    Replies: 1
    Last Post: 07-09-2002, 05:11 AM

Tags for this Thread