0

このコードの最後の部分の 2 つの文字のうちの 1 つだけをプログラムのインデックス 7 で調べるようにプログラムをコーディングするにはどうすればよいでしょうか。私は新しく、しばらくこれに取り組んでいます。これは私に苦労を与えており、本を読み続け、ビデオをダウンロードしていますが、これを取得していないようです.

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{

string string;

    // get character
cout << "\nEnter Email address ID: ";
getline(cin,  string );
cout << endl;
{
if (!isalpha(string[0]))
    cout << "first charactor needs to be a Letter"<< endl;

 if (!isalpha(string[1]))
     cout << "Second charactor needs to be a letter"<< endl;

 if (!isdigit(string[2])) 
    cout << "Third charactor needs to be a number"<< endl;

 if (!isdigit(string[3])) 
    cout << "Fourth charactor needs to be a number"<< endl;

 if (!isdigit(string[4])) 
    cout << "Fifth charactor needs to be a number"<< endl;

 if (!isdigit(string[5])) 
    cout << "Sixth charactor needs to be a number"<< endl;

if (!isdigit(string[6])) 
    cout << "Seventh charactor needs to be a number"<< endl;


if(!isalpha(string[7]))

 if(string != "n" || string !="p")      
    cout << "Eight charactor needs to be a N or P"<< endl;
{
}


cout << endl;
system("pause");
return 0;
}
 }
4

1 に答える 1

2

-->IsAlpha 整数がアルファベット文字を表すかどうかを判断します。
出力:

            Enter Email address ID: abcdef1@kmail.com

            Third charactor needs to be a number
            Fourth charactor needs to be a number
            Fifth charactor needs to be a number
            Sixth charactor needs to be a number
            Eight charactor needs to be a N or P

            Press any key to continue . . .

//-------------------------以下のように中かっこを変更してください------

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{

    string string;

    // get character
    cout << "\nEnter Email address ID: ";
    getline(cin,  string );
    cout << endl;
    {
        if (!isalpha(string[0]))
            cout << "first charactor needs to be a Letter"<< endl;

        if (!isalpha(string[1]))
            cout << "Second charactor needs to be a letter"<< endl;

        if (!isdigit(string[2])) 
            cout << "Third charactor needs to be a number"<< endl;

        if (!isdigit(string[3])) 
            cout << "Fourth charactor needs to be a number"<< endl;

        if (!isdigit(string[4])) 
            cout << "Fifth charactor needs to be a number"<< endl;

        if (!isdigit(string[5])) 
            cout << "Sixth charactor needs to be a number"<< endl;

        if (!isdigit(string[6])) 
            cout << "Seventh charactor needs to be a number"<< endl;


        if(!isalpha(string[7]))
        {
            if(string != "n" || string !="p")      
                {cout << "Eight charactor needs to be a N or P"<< endl;

                 }
        }

        cout << endl;
        system("pause");
        return 0;
    }
}
于 2013-10-31T06:59:57.267 に答える