I am a newbie to C++ and I'm not sure of anything at this point in time however,I got a problem with the starting phase of this program that well prompt the user to input a single character and output a inter4national Civil Aviation Word !!!!! The prolem that I have is that you have to enter a character before it will start and it closes after just one entry I don't see what is wrong!!!! Can somebody Help
Thanks for your time

#include "stdafx.h"
# include <iostream>

using namespace std;

int main()
    
{
    int a;
    char letter;
    cin>>letter;

    cout << "Enter a single capitalize character, Example A:";
    cin >> letter;
    
    switch (letter)
{
  case 'A': cout << "ALPHA";      // do something
            break;
  case 'B': cout << "Bravo";      // do something
            break;
  case 'C': cout << "Charlie";
            break;
  case 'D': cout << "Delta";
            break;
  case 'E': cout << "Echo";
            break;
  case 'F': cout << "Foxtrot";
            break;
  case 'G': cout << "Gulf";
            break;
  case 'H': cout << "Hotel";
            break;
  case 'I': cout << "India";
            break;
  case 'J': cout << "Juliet";
            break;
  case 'K': cout << "Kilo";
            break;
  case 'L': cout << "Lima";
            break;
  case 'M': cout << "Mike";
            break;
  case 'N': cout << "November";
            break;
  case 'O': cout << "Oscar";
            break;
  case 'P': cout << "Papa";
            break;
  case 'Q': cout << "Quebec";
            break;
  case 'R': cout << "Romeo";
            break;
  case 'S': cout << "Sierra";
            break;
  case 'T': cout << "Tango";
            break;
  case 'U': cout << "Uniform";
            break;
  case 'V': cout << "Victor";
            break;
  case 'W': cout << "Whiskey";
            break;
  case 'X': cout << "X-ray";
            break;
  case 'Y': cout << "Yankee";
            break;
  case 'Z': cout << "Zulu";
            break;
  default : cout << "Error";
}

    
    cin >> a;

    return 0;
}

Hi wheelz,
You should check the input with While loop.It's something like this:

while((cin >> letter) != '0')
{
       Your switch statement;
       And so... .;
}

Good luck.

Comments
Succinct and to the point - Salem

I don't think I understand the problem.

I am a newbie to C++ and I'm not sure of anything at this point in time however,I got a problem with the starting phase of this program that well prompt the user to input a single character and output a inter4national Civil Aviation Word !!!!!

So you prompt the user to enter a character.

The prolem that I have is that you have to enter a character before it will start...

Ummm, isn't this the definition of "prompt the user to input a single character"? Why would this be a problem?

... and it closes after just one entry

Bottom of the program:

case 'Z': cout << "Zulu";
            break;
  default : cout << "Error";
}

cin >> a;

    return 0;
}

Output the information, accept a character (which reads the [enter] from above -- remember, you entered a letter AND the ENTER key) and exit. The only problem I see is the program probably doesn't wait at the end. Change the top cin to getline to keep the input stream clean, read it into a string and move the first character of the string to letter and continue.

Also, #include "stdafx.h" i not necessary.

This article has been dead for over six months. Start a new discussion instead.