•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,813 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,571 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 4699 | Replies: 3
![]() |
•
•
Join Date: May 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi all
I have fingered out how to check the users input for their first and last name
This works fine.
If the user enters a number for their name they resave an error message.
But it only works for the first letter
How do I increment the check for each additional letter
int mainMenu::getName()
{
int i;
cout << "\tPlease enter your first name: ";
cin.get(firstName, 20).get();
while (isdigit(firstName[i]))
{
printf("\n\t\a%c[%d;%dmYou entered a Number ", 0x1B, BRIGHT, RED, BG_BLACK);
printf("%c[%dm", 0x1B, 0);
cout << firstName;
cout << flush;
printf(", %c[%d;%dmAs part of your first Name try agin.\n\n", 0x1B, BRIGHT, RED, BG_BLACK);
printf("%c[%dm", 0x1B, 0);
cout << "\tPlease enter your firstName: ";
cin.get(firstName, 20).get();
cout << endl;
}
cout << endl;
cout << "\tPlease enter your lastName: ";
cin.get(lastName, 20).get();
while (isdigit(lastName[i]))
{
printf("\n\t\a%c[%d;%dmYou entered a Number ", 0x1B, BRIGHT, RED, BG_BLACK);
printf("%c[%dm", 0x1B, 0);
cout << lastName;
cout << flush;
printf(", %c[%d;%dmEnter your last name try agin.\n\n", 0x1B, BRIGHT, RED, BG_BLACK);
printf("%c[%dm", 0x1B, 0);
cout << "\tPlease enter your lastName: ";
cin.get (lastName, 20).get();
}
firstName[0] = toupper (firstName[0]);
lastName[0] = toupper (lastName[0]);
cout << endl;
return 0;
}
Thank you,
manny
•
•
Join Date: Apr 2007
Posts: 102
Reputation:
Rep Power: 2
Solved Threads: 17
#include<iostream> usingnamespace std; #include<string> int main() {char y; cout << "Enter a character or number: _\b"; cin >> y; if(!isdigit(y))}cout << "It's a Letter";elsecout << "It's a Number";cout << '\n'; return 0;
•
•
•
•
#include<iostream> usingnamespace std; #include<string> int main() {char y; cout << "Enter a character or number: _\b"; cin >> y; if(!isdigit(y))}cout << "It's a Letter";elsecout << "It's a Number";cout << '\n'; return 0;
My friend, I think you are assuming too much of that if statement. What if the entered input is a space or a new line or " ?. Would that be considerate a letter?.
Last edited by Aia : May 16th, 2007 at 12:03 am.
"No man's life, liberty, or property is safe while the legislature is in session." ~ Mark Twain
•
•
Join Date: May 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
My friend, I think you are assuming too much of that if statement. What if the entered input is a space or a new line or " ?. Would that be considerate a letter?.
Hi
Thank you but I am asking the user to enter their name. And confirm that a letter has ban entered if not output a message I have the first part worked out
If the first letter is a digit the user resaves a message
I am trying to increment this processes for each character entered by one.
while (isdigit(firstName[i]))
{
printf("\n\t\a%c[%d;%dmYou entered a Number ", 0x1B, BRIGHT, RED, BG_BLACK);
printf("%c[%dm", 0x1B, 0);
cout << firstName;
cout << flush;
printf(", %c[%d;%dmAs part of your first Name try agin.\n\n", 0x1B, BRIGHT, RED, BG_BLACK);
printf("%c[%dm", 0x1B, 0);
cout << "\tPlease enter your firstName: ";
cin.get(firstName, 20).get();
cout << endl;
}
Last edited by cscgal : May 16th, 2007 at 8:28 pm. Reason: Excessive color removed per forum policy
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Looking for a way to check for invalid inputs and or are functions easier ? (C++)
- run program and rename file script help please (Shell Scripting)
- Java and recursion (Java)
- Number puzzle help (C)
- Need help displaying when user enters negative number? (C++)
- Nested loop that runs until user enters 'q' (C++)
Other Threads in the C++ Forum
- Previous Thread: Is it a problem due to scope or compiler ?
- Next Thread: Creating Console Applications Using Visual C++ Express Edition 2005



Linear Mode