array

i have a program that says input 10 letters and it will be outputed and right after that the letters should appear in reverse form..i have made a program but it didn't output the reverse form...here's my program using arrays:
//John Michael T. Matubis

//july 7, 2008

//ICSM122

//prelimenary exam



#include<iostream>

using namespace std;

char answer(char letter_par);

int main()

{

int i;

do

{

system("cls");

cout << "Please enter 10 letters:\n";

do

{

cin >> letter[i];

i++;

}while(i<10)

cout << "The reverse form is \n";

reverse_form=answer(letter [i]);

cout << reverse_form << endl;

system("pause");

}

while(repeat='y');

cout << "do you want to repeat?Y for Yes and N for no.\n";

cin >> repeat;

return 0;

}

char answer(char letter_par)

{

int k=9;

while (k>=10)

cout << letter[k];

k--;

return 0;

}

the program should be like this:
enter 10 letters:helloworld
the reverse form is:dlrowolleh...please tell me teh error so that i could correct it...tnx
You use i++; but you haven't give any value to i...
You then use the variable letter but you never declared it.
You forgot the ";" after the }while(i<10)
You forgot to declare "repeat" and "reverse_form" also.

When you want to pass an array to a function you use the following syntax:
1
2
3
4
5
6
7
8
void myFunc(myArray[]){//You use the array name with brackets next to it
   //your function code here
}
int main(){
   char chArray[5];
   chArray[0] = 's';
   myFunc(chArray); //You just use the array name here
}

There is also a logic error in the function answer.

Hope this helps
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
 int chararray[10];
 cout<<"Enter 10 letters";
 int aux;
 for(aux=0;aux<10;aux++)
       {
               cin>>chararray[aux];
       }
 for(aux=9;aux>=0;aux--)
      {
               cout<<chararray[aux];
      }
return 0;
}

Without other function(hope it works,i haven't tested it)
Topic archived. No new replies allowed.