Hi Tinkerbell,
Firstly, you are using deprecated headers.
It should be:
Code:
#include <iostream>
using namespace std;
If your teacher/lecturer tells you otherwise he needs to
be corrected. Why not be the one to correct him.
Secondly, you asked what is a loop?
A loop or "for loop" is vitally important in programming.
Let's say you wanted your program to count from 1 to 1000. Now you could do this:
Code:
cout<<1;
cout<<2;
cout<<3
.
.
.
cout<<1000;
This is obviously tedious? There is a much quicker way which involves using a for loop.
The way you write it is as follows:
Code:
for(int a=0; a<1000; a++)
{
cout<<a;
}
The important bits.
Now the "int a=0;" is your starting value.
The "a<1000" is your end value.
And the 'a++' tells you how much to add to the previous value. It is similar to saying a= a+1.
So if you wanted to count up in tens you would write:
Code:
for(int a=0; a<1000; a=a+10)
{
cout<<a;
}
So how does this help you with your example?
Well you can use the for loop as a pointer to the position in your array.
So how would you print out the contents of your array, from [0] to [5]?
for(int a=0; a<6; a++)
{
cout<<name[a];
}
Ok now all you have to do is figure out what you need to change to print out the array backwards. What would be the start value, the end value and how would the
a++ differ?
Have a go.
Once you've done that then read up on functions