April 26th, 2003, 04:57 AM
I want to create a menu that can read user input eg. "Peter Corbell" an the program must be able to check that the input is all letter with space between eg.Peter and Corbell and if input is a number, it print "error" message and prompt user to enter again. How am I going to program it as I am a novice to the and could not find or do not know how to find solution even after a few weeks of trying with reference to book.
Can anyone please help me. Thank you.
April 26th, 2003, 06:52 AM
1)Read in the user data with cin.getline()
2)isalpha() will check to see if each char is a letter.
3)If you look at an ASCII code table, you will see that a space is stored as the integer 32, so you can check to see if there is a space somewhere between the first char and the last char of the input.
4)You should consider spending a few months doing easier programs.
5)Read Ivor Horton's Beginning C++(skip the overly complex bitwise operator section in Chapter 3)
Last edited by 7stud; April 26th, 2003 at 06:54 AM.
April 27th, 2003, 12:47 AM
Just to say thank you.
Thank to your advice and recommendation of the book. I will try to find the book. I am not sure on how to use the function in 1 and 2.
I refer to my book and isalpha() is not easy for me. Please explain it to me in much simple way which relate to my problem if you are willing. For the name print out problem I had posted, my solution is to change the %s to %[^\n] in scanf and it works.
Thank you for the cin.getline you suggest but I do not know how to use it. Thank you for helping again.
Last edited by EDIT; April 27th, 2003 at 01:16 AM.
April 27th, 2003, 05:52 AM
1) See here:
......cout<<"Input Error!: "<<text[i]<<endl;
if(text[i] == ' ') count++;
Last edited by 7stud; April 28th, 2003 at 04:22 AM.