i am suppossed to write a program using an array of strings to hold the words of the ICAO alphabet, and index the array by the positions of the letters of the alphabet. I started it off but cannot figure it out please help!!

#include <iostream>



const int n_row=26;
const int n_col=2;
const char tarray(n_row)(n_col)= {
{‘A’, ‘Alpha’},
{‘B’, ‘Bravo’},
{‘C’, ‘Charlie’},
{‘D’, ‘Delta’},
{‘E’, ‘Echo’},
{‘F’, ‘Foxtrot’},
{‘G’, ‘Golf’},
{‘H’, ‘Hotel’},
{‘I’, ‘India’},
{‘J’, ‘Juliet’},
{‘K’, ‘Kilo’},
{‘L’, ‘Lima’},
{‘M’, ‘Mike’},
{‘N’, ‘November’},
{‘O’, ‘Oscar’},
{‘P’, ‘Papa’},
{‘Q’, ‘Quebec’},
{‘R’, ‘Romeo’},
{‘S’, ‘Sierra’},
{‘T’, ‘Tango’},
{‘U’, ‘Uniform’},
{‘V’, ‘Victor’},
{‘W’, ‘Whiskey’},
{‘X’, ‘X-Ray’},
{‘Y’, ‘Yankee’},
{‘Z’, ‘Zulu’} };


void main()
{
char phrase[80], holdPhrase[80], letter, answer;
int x, y;


cout<<Enter a Phrase;
cin.getline(phrase, 79);


int sizeOfPhrase = strlen(phrase);


for (x=0; x< sizeOfPhrase; x++)
{
if (phrase[x]== ’ ‘)
holdPhrase[x]= ’ ‘;
else
holdPhrase[x]= ’-‘;
}


holdPhrase[x]=’\0’;


cout<<endl<<holdPhrase<<endl;
int found=0;


do
{
cout<<Enter a letter please :;
cin>>letter;
found =0;


for (y=0; y< sizeOfPhrase; y++)
{
if (letter == phrase[y]
{
found =1;
holdPhrase[y]=letter;
}
}


if (found ==0)
cout <<endl<<Letter<<letter<<not in phrase.;


else
cout <<endl<<holdPhrase<<endl;


cout<<\n\nContinue y/n:;
cin>>ans;
}
while (toupper(ans) !=’N’);


cout <<\n\n Program completed, \n;


}

First of all avoid the '\221' and '\222' and '\224' characters, the compiler does not like them, use ' or " where appropriate!

Also use {"A", "Alpha"} and so on in your array of strings.
Change ans to answer

Once you get the program to compile you can work on the porpose.

Pointers and arrays of pointers are always problematic to understand, hopefully these changes will clarify for you.

#include <iostream>
using namespace std;
 
char *tarray [] = {"Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Gulf","Hotel",
"India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa",
"Quebec","Romeo","Sierra","Tango","Uniform","Victor","Wiskey","X-Ray",
"Yankee","Zulu"};
 
int main (void)
{
char phrase [80], holdPhrase [80], letter;
 
cout << "Enter Phrase: ";
cin.getline (phrase, 79);
int sizeOfPhrase = strlen (phrase);
 
for (int x = 0; x < sizeOfPhrase; x++)
{
if (phrase [x] == ' ')
holdPhrase [x] = ' '; else holdPhrase [x] = '-';
}
holdPhrase [x] = 0;
 
cout << holdPhrase << endl;
 
do
{
cout << "Enter letter please: ";
cin >> letter;
cout << tarray [(letter & 0x5f) - 'A'] << endl;
 
cout << "Again: ";
cin >> letter;
} while ((letter &0x5f) == 'Y');
 
return 0;
}

In your example you never used tarray, so I assume I have it in the right place. You can replace

letter & ox5f;
toupper (letter);

either converts input to uppercase.

ok so here is that. Now what ??
#include <iostream>


const int n_row=26;
const int n_col=2;
const char tarray(n_row)(n_col)= {
{"A", "Alpha"},
{"B", "Bravo"},
{"C", "Charlie"},
{"D", "Delta"},
{"E", "Echo"},
{"F", "Foxtrot"},
{"G", "Golf"},
{"H", "Hotel"},
{"I", "India"},
{"J", "Juliet"},
{"K", "Kilo"},
{"L", "Lima"},
{"M","‘Mike"},
{"N", "November"},
{"O", "Oscar"},
{"P", "Papa"},
{"Q", "Quebec"},
{"R", "Romeo"},
{"S", "Sierra"},
{"T", "Tango"},
{"U", "Uniform"},
{"V", "Victor"},
{"W","‘Whiskey"},
{"X", "X-Ray"},
{"Y", "Yankee"},
{"Z", "Zulu"} };

void main()
{
char phrase[80], holdPhrase[80], letter, answer;
int x, y;

cout<<Enter a Phrase;
cin.getline(phrase, 79);

int sizeOfPhrase = strlen(phrase);

for (x=0; x< sizeOfPhrase; x++)
{
if (phrase[x]== ’ ‘)
holdPhrase[x]= ’ ‘;
else
holdPhrase[x]= ’-‘;
}

holdPhrase[x]=’\0’;

cout<<endl<<holdPhrase<<endl;
int found=0;

do
{
cout<<Enter a letter please :;
cin>>letter;
found =0;

for (y=0; y< sizeOfPhrase; y++)
{
if (letter == phrase[y]
{
found =1;
holdPhrase[y]=letter;
}
}

if (found ==0)
cout <<endl<<Letter<<letter<<not in phrase.;

else
cout <<endl<<holdPhrase<<endl;

cout<<\n\nContinue y/n:;
cin>>answer;
}
while (toupper(ans) !=’N’);

cout <<\n\n Program completed, \n;

}

Pointers and arrays of pointers are always problematic to understand, hopefully these changes will clarify for you.

#include <iostream>
using namespace std;
 
char *tarray [] = {"Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Gulf","Hotel",
"India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa",
"Quebec","Romeo","Sierra","Tango","Uniform","Victor","Wiskey","X-Ray",
"Yankee","Zulu"};
 
int main (void)
{
char phrase [80], holdPhrase [80], letter;
 
cout << "Enter Phrase: ";
cin.getline (phrase, 79);
int sizeOfPhrase = strlen (phrase);
 
for (int x = 0; x < sizeOfPhrase; x++)
{
if (phrase [x] == ' ')
holdPhrase [x] = ' '; else holdPhrase [x] = '-';
}
holdPhrase [x] = 0;
 
cout << holdPhrase << endl;
 
do
{
cout << "Enter letter please: ";
cin >> letter;
cout << tarray [(letter & 0x5f) - 'A'] << endl;
 
cout << "Again: ";
cin >> letter;
} while ((letter &0x5f) == 'Y');
 
return 0;
}

In your example you never used tarray, so I assume I have it in the right place. You can replace

letter & ox5f;
toupper (letter);

either converts input to uppercase.

Much much better. Thanks I will compile it when i get home. From your knowledge is there anything else that I need to add?

Any other suggestions I would have are related to my personal preference as to coding style which isn't really realative to your situation. Generally the body of your application is sound or at least it achieves the objective. All you have to do now is add the part where holdPhrase is modified dependant upon users input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.