#include <iostream>
#include <string>
using namespace std;
bool custNum(char [], int);
int main()
{
const int size = 8;
char custmor[size];
cout << "Enter a customer number in the form ";
cout << "LLLNNNN\n";
cout << "(LLL = letters and NNNN = numbers): ";
cin.getline(custmor, size);
if(custNum(custmor, size))
cout<<"That's a valid id number"<<endl;
else
cout<<"That's not a valid id number"<<endl;
return 0;
}
bool custNum(char custNum[], int size)
{
int count;
for(count = 0; count<3; count++)
{
if(!isalpha(custNum[count]))
return false;
}
for(count = 3; count <size - 1; count++) //3<7 , 4
{
if(!isdigit(custNum[count]))
return false;
}
return true;
}
私は3文字の文字配列とABC1234のような4個の数字をループしたいが、2番目のforループ(size - 1)の条件は得られなかった。どのようにそれは条件をテストするたびに動作しますか?文字配列をループするC++
を必要とするコードは、あなたが使うべき –
私はどこにもサイズ変数宣言を見ることができないで「壊します。」 "return false"の代わりに –
彼は2番目のループが実行されない理由について質問していると思いますか? –