944,144 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10535
  • C++ RSS
Jan 30th, 2005
0

Insert a number in an array

Expand Post »
im trying to insert a number into an array but when i insert a number it deletes the last number instead of increasing the array size by one....this is the code i have:

void Insertion(float T[100],int size)
{
float target = 0.0;
cout<<"Enter the number you are inserting"<<endl;
outData<<"Enter the number you are inserting"<<endl;
cin>>target;

int k=0;
while((k< size) && (T[k] < target))
k++;
for(int index = size -1; index>=k;index --)
{
T[index + 1] = T[index];
}

T[k] = target;
size = size + 1;
}

Thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Foxtildawn is offline Offline
15 posts
since Jan 2005
Jan 31st, 2005
0

Re: Insert a number in an array

as jwenting said you CANT increase the size of an array, you have to make a seperate bigger one and copy, or use a linked list / vector solution. No need to x2 post!
Reputation Points: 16
Solved Threads: 6
Posting Pro in Training
1o0oBhP is offline Offline
445 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: help with inserting a number into an array
Next Thread in C++ Forum Timeline: Colour & graphics in DOS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC