# arrays

• 07-27-2008, 08:26 PM
hasysf
arrays
Hello this is my first question on this forum
I need to ask a question
what is the difference in storing a value in array and adding a value in array
my psuedocode and both the requirements provided separately
• 07-27-2008, 08:53 PM
matt_well
I read my Java book saying that
double temperature[]; // declare array
temperature = new double[10]; //allocate space for array
Which means the temperature have ten double storage location.
• 07-27-2008, 08:57 PM
hasysf
yaa thats true but the thing is that is there difference to store a value entered by a user in an array
and add the value entered by a user in the array
i am confused

• 07-27-2008, 09:07 PM
Norm
Quote:

to store a value entered by a user in an array
and add the value entered by a user in the array
That sounds like two different ways to same the same thing.
To put a value into an array: arrayN[i] = value;
Not sure what you mean by add. Is 'to add' the same as to sum up two items? To add x to y you would code x = x + y;
But when talking about an array, to add to an array could mean to make the array longer (add to its length) or it could mean to add to an element in an array: arrayN[i] += value;

Could you give an example of the two things you are asking about. In both cases you have a value entered by a user.
Now what are the two things you want to do with that value?
• 07-27-2008, 09:32 PM
hasysf
Sure
/* Compare the user input to the unique numbers in the array using a for
31 statement. If the number is unique, store new number */
32
33 /* add the user input to the array only if the number is not already
34 in the array */
35 if ( !containsNumber )
36 {
37 /* Write code to add the number to the array and increment
38 unique items input */
39 } // end if

this is the psuedocode for the part of the program
any suggestions?
• 07-27-2008, 10:07 PM
hasysf
hello norm can u check the code that i sent you and tell me what it means.
• 07-27-2008, 11:38 PM
Norm
I'll restate the problem.
If you have a some playing cards (an array) and a user hands you a new playing card, look thru the cards you already have(use a for loop, comparing the new one to each one you have) and if the new card is unique(you get to the end of the cards and don't see any matches), add it to the group(insert the new one at the end).
• 07-28-2008, 12:33 AM
hasysf
thanks norm
this is really a nice example to help me go aroung
• 07-28-2008, 12:36 AM
hasysf
Compare the user input to the unique numbers in the array using a for
31 statement. If the number is unique, store new number */

what is meant by that norm
• 07-28-2008, 12:52 AM
Norm
Where did you get the problem statement? Do you have an instructor or a textbook?
The for statement is used to control looping. for(i=0; i <10; i++)
The == operand is used for comparing two primitives like numbers or characters. if(a == b)
The if statement is used to control execution based on a condition. (a == b)
Unique is an english word.
To store is to save the number.
• 07-28-2008, 12:59 AM
hasysf
hello sir
I dont think i was expecting this answer from you. But anyways thanks for replying and by storing i meant by storing in the simple variable or in an array
thanx
• 07-28-2008, 03:33 AM
Norm
Quote:

storing in the simple variable or in an array
int x = value; // store value in simple variable
x[i] = value; // store value in an array
• 07-28-2008, 03:38 AM
hasysf
thanks norm