0

我如何对我的程序进行编码以仅查看程序的索引 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 回答