Expand|Select|Wrap|Line Numbers
- #include<iostream>
- #include<fstream>
- #include<cstdio>
- #include<string>
- #include<ctime>
- using namespace std;
- int main()
- {
- // validation of input
- bool isValid=true;
- int i=0;
- char chrId[3];
- string id="";
- cout<<"\n Enter your initials ";
- getline(cin,id);
- if(id.length()!=2)
- {
- cout<<"\n Please only enter two alpha initials "<<endl;
- getline(cin,id);
- }
- strcpy(chrId,(id.substr(0,2).c_str()));
- while(isValid && i < 2)
- {
- if(isalpha(chrId[i])==false)
- {
- cout<<"\n Please only enter two alpha initials "<<endl;
- isValid=false;
- getline(cin,id);;
- }
- chrId[i]=toupper(chrId[i]);
- i++;
- }
- cout<<"\n Initials entered are "<<chrId<<endl;
- system("PAUSE");
- return 0;
- }