Thread: Characters in a Magic Square Program

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    9

    Characters in a Magic Square Program

    My friend and I have almost finished the Magic Square Program. All that is left is have the program check to see if the user inputted a Letter instead of a number. (i.e. "Input square[0][0]: g") after g has been inputted into the program instead of a number 1-9, the program will just keep displaying the same phrase over and over and keep repeating until you physically exit the program. Is there any way using the "isalpha" function and incorporate it into the program and have the program display the if it is a letter that was inputted. Any help will be appriciated.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Something along these lines?
    Code:
    #include <cctype>
    #include <iostream>
    #include <limits>
    
    using namespace std;
    
    int main()
    {
      char val;
    
      for ( ; ; ) {
        cout<<"Enter a number 1-9 or G to quit: ";
        if ( !cin.get ( val ) || !isdigit ( val ) )
          break;
        cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
        cout<< val <<endl;
      }
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Replies: 51
    Last Post: 12-07-2008, 08:08 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. help with magic square
    By dragon_heart in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2004, 05:56 PM
  5. Magic Square and Tic Tac Toe
    By curlious in forum Game Programming
    Replies: 3
    Last Post: 07-28-2003, 05:50 PM