CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: input sngl char

  1. #1
    Guest

    input sngl char

    How do I take in a input word but only look at the first character?
    cin >> Minus
    (but only look at the M)


  2. #2
    Join Date
    Jul 1999
    Location
    Pasadena, CA - USA
    Posts
    351

    Re: input sngl char

    Hi,

    is this what you are asking?


    char cFirstChar;
    char Minus[20];

    cin >> Minus;
    cFirstChar = Minus[0];






    Regards,

    Paul Belikian

  3. #3
    Guest

    Re: input sngl char



    int main()
    {

    char command_character;
    double r1;
    double r2;
    double acc;


    cout.setf(ios::fixed, ios::floatfield); //Set up floating pt.
    cout.setf(ios::showpoint); // output format
    cout << setprecision(1);

    DisplayMenu();//has a cout stating to type in char but if more than one letter is typed in it goes crazy.

    cin >> command_character;


    while ((command_character != 'Q') &&
    (command_character != 'q'))
    {

    switch(command_character)
    {
    case '+':
    case 'a':
    case 'A':
    Addition(r1,r2, acc);

    break;





  4. #4
    Join Date
    Jul 1999
    Location
    Pasadena, CA - USA
    Posts
    351

    Re: input sngl char

    I think you need to make sure command_character is big enough to hold as many chars that could be typed in.
    Right now char command_character is only 1 char long. You need to make an array and pass
    only the first char...



    #define MAX_INPUT_SIZE 100

    int main()
    {
    char command_character[MAX_INPUT_SIZE];
    double r1;
    double r2;
    double acc;

    cout.setf(ios::fixed, ios::floatfield); //Set up floating pt.
    cout.setf(ios::showpoint); // output format
    cout << setprecision(1);

    DisplayMenu();//has a cout stating to type in char but if more than one letter is typed in it goes crazy.

    cin >> command_character;
    while ((command_character[0] != 'Q') && (command_character[0] != 'q'))
    {
    switch(command_character[0])
    {
    case '+':
    case 'a':
    case 'A':
    Addition(r1,r2, acc);
    break;







    Regards,

    Paul Belikian

  5. #5
    Guest

    Re: input sngl char

    Thanks,Paul my program is now finished, up and running
    thanks to you!!!
    Duane


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured