c++ - How to arrange the loops to check for numbers -
I have a program that reads the credit card number. I think it ensures that 16 numbers are added, no letters, and want to add as many spaces (although they are not counted on numbers). Is there a function or set of functions to do this, or would I just want to make a bunch of times and if the loops that use isdigit () and islpha (), through an element of the array at a time Do you go
Four Card New [32]; Cout & lt; & Lt; "Enter credit card number:"; Cin.getline (Cardnom, 32); // Read the full line for the name
There are several things you can do . For example using std :: find_if with custom idea, for example: bool IsCharIllegal (char ch) {// returns true or false that your Accurate requirements are based on} then: get it automatically = std :: find_if (card new, cardam + 32, i.e. e.l. lagal ); If (this found! = CardNum + 32) // invalid character was entered! There is one case to use std :: string instead of a raw char array: std :: string cardnom; Cout & lt; & Lt; "Enter credit card number:"; Std :: cin & gt; & Gt; CardNum; Followed by :
Automatically do itfound = std :: find_if (cardNum.begin (), cardNum.end (), ischirallegal); If (this found! = CardNum.end ()) // invalid character was entered! This helps to avoid magic 32 and allows any length.
Comments
Post a Comment