Thread: array program trouble

  1. #1
    Registered User
    Join Date
    Oct 2006

    array program trouble

    I have a program I am writing that I am having a lot of trouble with. I need to write a program that takes in a string and then spells that string using the ICAO alphabet. The ICAO alphabet needs to be in an array. How would I set the array up? Thank you. Here is the alphabet:

    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

  2. #2
    ... arjunajay's Avatar
    Join Date
    May 2005
    Like you set up normal arrays ???
    You may also want to use std::map if you like.
    std::string array[] = { "alpha", "bravo", ... "zulu" };
    char ch = 'A';
    std::cout<<array[ch - 65];
    std::cout<<array[ch - 'A'];

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Seattle, WA
    Why not:
    const std::string ICAO[] = { "Alpha", "Bravo", "Charlie", /*...*/ };
    Then all you have to do is figure out how to get the correct subscript.

    Edit: A few minutes too slow...
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."

  4. #4
    Registered User
    Join Date
    Aug 2006
    #include <string>
    std::string ICAO[26] = {Alpha, Bravo, ...};
    I think something like above may be one way to approach the problem. I'm pretty sure the index of the array is defined here, but the index may be required to be absent in this type of declaration.

    The above will work because if you note in an ASCII table A-Z is equivalent to the integers 65-90 so you can just take a letter say "B" convert it to an integer than subtract 65 to get the valid index into the array, which would be 66-65=1.

    I'm sure there are countless ways to approach this problem.

    Edit: A few minutes too slow times 2....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing a C program for class....
    By Bizmark in forum C Programming
    Replies: 10
    Last Post: 11-13-2007, 10:31 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. help with small program. array issue
    By InvariantLoop in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 12:26 PM
  4. my program wont read vector array
    By MKashlev in forum C++ Programming
    Replies: 5
    Last Post: 08-10-2002, 03:51 PM
  5. problem with 2d array program.
    By Niloc1 in forum C Programming
    Replies: 1
    Last Post: 04-08-2002, 05:47 PM