Moving an array and adding a value

I want to move values of an array to the right so that a user inputted value will fit in the user desired location:

This is my program so far, its not finished obviously but I don't know where to go from here...

#include <iostream>
using namespace std;

int main ()
{
int intArray [10];
int i;
int V = 0;
int location;

cout << "Please input a value for V: ";
cin >> V;

for (i = 0; i < 10; i++) //0-9
{
cout << "Please input a value for Array[" << i <<"]: ";
cin >> intArray[i];
}

cout << "Please input a location between 0-9 for the value 'V' to be placed: ";
cin >> location;

for (i=0, i < location; i++)

(Rest of program here!)


system("pause");
return 0;
}
I think you mean something like this

1
2
3
4
5
6
7
8
9
10

    int   location = 5;

    for (int i=location;i<10-1;i++)
    {
        intArray[i+1] = intArray[i];
    }

    intArray[location] = V;


hopefully this was useful
Shredded
Why the location = 5

and

i<10-1 in the for loop?
Right I have cracked it....heres the final program encase anyone else needs help:

#include <iostream>
using namespace std;

int main ()
{
int intArray [10];
int i;
int V = 0;
int location;

cout << "Please input a value for V: ";
cin >> V;

for (i = 0; i < 10; i++) //0-9
{
cout << "Please input a value for Array[" << i <<"]: ";
cin >> intArray[i];
}

cout << "Please input a location between 0-9 for the value 'V' to be placed: " "\n";
cin >> location;


for (i=9; i > location; i--)
{
intArray [i] = intArray[i-1];
}

intArray[location] = V;

for (i=0; i<10; i++)
{
cout << i << ": " << intArray[i] << "\n";
}

system("pause");
return 0;
}
Topic archived. No new replies allowed.