C++/C++

Advertisement


Question
Dear sir

When i ask a user to input a number 3 digits long how do you ensure that the first digit is not one (1)?

thank you.

Answer
Dear Noorain,
Thankyou for your question.

Well, you've asked me, you want to ask a user to
enter a three digit number, and you wana put a
condition that it shouldn't contain '1' as the first
digit. Then you have to find such a condition that
will divide the number by a constant value whenever
you enter it, and it calculates the quotient,
for example,

User enters : 234

internally i would bring condition like

int number ;

number = entered number / 100 ;
It will store the quotient in the variable number.
Like i said you entered 234

it would be

number = 234 / 100 ;
It would store 2 in the number and make sure that the
number is not 1 by putting simple condition like this

if ( number != '1' )
cout<<"It is a valid number";
else
cout<<"It contains 1 as the first digit";

You should find out the 100th Number position in the
number. Like i did in the above example. I hope this
helps you a little.

Don't be afraid to ask, if you get stucked somewhere.
Best of Luck,
Professional

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Professional

Expertise

I can answer any question about functions,pointers,structures,object oriented programming basics of classes and data structures.My strong field is structured programming.

Experience

I have got 2 years experiece under C . I am able to answer about the structured concepts pointers to a little extent,OOP concepts. I have also experience in data Strucutres like Linked List, Stacks , Queues, Heaps, B Trees, Red Black Trees. I will try to satisfy with my knowledge. I am the Student of an expert here Martin, what i have learnt today, i just owe my every knowledge to him. He is the greatest.

©2016 About.com. All rights reserved.