473,224 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

how to showing error message while integer is entered?

1
I'm new to C++ and am trying to write a code that will prompt the user to enter a character. my question is: how do i enter a condition that will printf an error message and prompt the user for a new entry?? i understand how it works, i just dont know what the condition is to recognize if a integer is enter. i also don't know what the condition is to recognize if a character is entered... my assignent is do today and i am stuck on that one part.. please help!
Jun 17 '07 #1
3 1655
DeMan
1,806 1GB
Hi Josh K,

Welcome to thescripts. I'll move this post to the c/c++ forum where more experts will see it. If you are using printf and scanf, you can use the formaters %d, %c (for integer (d) and character (c)) I believe using cin and cout the problem is even simpler, but a c++ expert may correct me.

It's possible that %d will still accept a character and convert it to it's decimal equivalent, but if you read everything in as a character string, you can (quite trivially) creata a method to determine whether each character is a digit or letter....

Passing you over to c/c++ now....
Jun 17 '07 #2
Yep. Look for an ASCII table that lets you convert between letters/codes and then just use a bunch of if statements to see if it (the passed-in char) corresponds to any digit. I think there's something in the STL that does something similar, head on over to www.cplusplus.com and look at the reference for ctype.h, I THINK. Should be something like isalpha() (that can be used too, in a pinch) or isnumber() or something along those lines. Then printf away! (although as DeMan pointed out cout and cin are *much* easier to use)
Jun 18 '07 #3
I'm new to C++ and am trying to write a code that will prompt the user to enter a character. my question is: how do i enter a condition that will printf an error message and prompt the user for a new entry?? i understand how it works, i just dont know what the condition is to recognize if a integer is enter. i also don't know what the condition is to recognize if a character is entered... my assignent is do today and i am stuck on that one part.. please help!
Hello josh K,
for ur problem u need to know ASCII values of alphabets and numbers..
once u will get them..then u ask for input. and chk its ASCII value if it comes in between 48 to 57 then u can print error msg and ask for input again..
48 to 57 is ASCII values for (0 to 9)..
- have a nice time.
Jun 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Christaaay | last post by:
I have been using the code below successfully for almost a year. yesterday, I began getting a run time error 6 (overflow). I am using the code in an Access 2000 database. Can anyone help me...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
2
by: JRamirez | last post by:
Need help cannot figure out where I made the error. -------------------------------------------------------------------------------- Can someone view what I have, I need help I cannot figure out...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
11
by: JeffP | last post by:
Just have a small problem with boolean fields in a list box showing as 0 and -1, not Yes/No or True/False. Is there any fix to this? -- Jeff "More Access Stuff." http://www.asken.com.au
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.