C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 26th, 2003, 03:57 AM
EDIT EDIT is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 4 EDIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Menu.

Hello,
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.

Reply With Quote
  #2  
Old April 26th, 2003, 05:52 AM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,327 7stud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 50 sec
Reputation Power: 9
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 05:54 AM.

Reply With Quote
  #3  
Old April 26th, 2003, 11:47 PM
EDIT EDIT is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 4 EDIT User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Just to say thank you.

7stud,
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 12:16 AM.

Reply With Quote
  #4  
Old April 27th, 2003, 04:52 AM
7stud 7stud is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2001
Posts: 1,327 7stud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 44 m 50 sec
Reputation Power: 9
1) See here:

http://www.cplusplus.com/doc/tutorial/tut3-2.html

2)
#include<cctype>//for isalpha()

char text[50];
cin.getline(text, 50);
if(!isalpha(text[i]))
......cout<<"Input Error!: "<<text[i]<<endl;

3)
int count=0;
if(text[i] == ' ') count++;
if(count==0)
.....cout<<"Input Error"<<endl;

Last edited by 7stud : April 28th, 2003 at 03:22 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Menu.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway