C++/C++

Advertisement


Question
Dear Eddie

When a user enters a number, for example stock number, how do you ensure that the first digit is not one (1)?

Thank you.

Answer
Hello Noorain,

To ensure this, it just requires a little bit of error checking:

// in main
int num;

cin >> num;

if(num == 1)
// error check.

If it also includes high numbers, the following will work

if(num >= 10 < 20 || num >= 100 < 200)
// error check

And so on.

I hope this information was helpful.

- Eddie  

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.