Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

In C++ How can I tell the difference between integers and characters?

Status
Not open for further replies.

Robertss

Newbie level 1
Newbie level 1
Joined
Nov 28, 2012
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,290
I am currently learning C++ and I have been asked to make a program which will calculate the interest that would be paid on a deposit of a given size. One of the requirements is that we display an error message when non-integer data is entered.

I however cannot work out how to detect if non-integer data has been entered. If anyone could provide an example of how this problem is solved it would be much appreciated!
 

By non-integer do you by any chance mean non-numeric ?

If so, all you need to do is check if your entered ascii character lies within 0x30 -0x39. These being the codes for key press 0..9
 

try this:
int a
if(!(cin>>a))
cout<<"error"
else if . . . .
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top