I need protection input for decimal number.
Terms:input of decimal +/- number;
at start of input mustn't be ".";
after input 0(at start),write ".";
after first "." mustn't be entered second ".";
if user enter second ".",program deletes to the first ".";
I'm beginner so it would be good to write in beginner's style :D
If someone help me,i will be very grateful! :)
I think, that taking the input as a string or char woulb be right and after input is made you scan the line for these kind of things. If first character is . then it asks a new input, if there are more than one . then the first one is removed.
i = 0
getline(cin,input_line)
while(chec the condition that you are not at the end of the stirng){
found = input_line.find(".")
if(something to check that on the location f found there really is "." {
i = i + 1
array or something to save the number
}
}
if(i == 2){
chooce second decimal
rewrite the string using the second decimal}
do what ever you want to do with it.
I dotn know all the commands, but in rough, this is how it should work.
YOu can simply check the input validation by but a if statement..
int num;
cin >> num;
if(num%2==0 || num%2==1 || num%2==-1)
ok.. do your proceddure
else
take input again...