This is my code:
#include<stdio.h>
#include<iostream>
#include<string>
#include<conio.h>
#include<fstream>
using namespace std;
class TESTnonteaching
{
private:
string oname[3];
string osir_name[3];
int oid[3];
public:
int count3;
void TESTadd();
void TESTsearching();
//void editing();
//void TESTdisplay3();
void TESTsetcount3()
{ count3=0 ;
}
};
//ADDING STAFF//
void TESTnonteaching::TESTadd()
{
if(count3>=3)
{cout<<"NO SPACE LEFT"; return;
}
cout<<"ENTER YOUR NAME \n";
cout<<"Terminate with '$' "<<endl;
getline(cin,oname,'$');
//IF THE USER PRESSES AN INTEGER
/*if( oname == int intValue )
goto k3;
k3:
string IntToString(int intValue) {
char *myBuff;
string strValue;
// Create a new char array
myBuff = new char[100];
// Set it to empty
memset(myBuff,'\0',100);
/............................................................/
//*memset (void *source, int value, size_t num);.
//Know that source is a pointer to the block of memory to fill and value is
//the character to be set. This byte value is internally converted to an unsigned char. //Num is the number of be set. Memset will set the first num bytes of the memory pointed to by source to the specified value and return source.
//Understand that the C++ memset function is kept in the cstring library.
// You may need to include the string.h header file to use this function.
/................................................................/
Convert to string
itoa(intValue,myBuff,10);
//Copy the buffer into the string object
strRetVal = myBuff;
// Delete the buffer:-
delete[] myBuff;
return(strValue);
}
*/
cout<<"ENTER YOUR SIR NAME \n";
getline(cin,osir_name,'$');
//IF THE USER ENTERS A NON-ALPHABETICAL VALUE
if( osir_name == int intValue )
goto k3;
G1:
cout<<"ENTER YOUR ID NUMBER\n";
cin>>oid[count3];
/* {
char TESTarray[3]="";
cin >> TESTarray;
for (int index = 0; index < 256 ; ++index)
{
if (TESTarray[index] == '\0')//test for end of null terminated string
break;
if (isalpha(TESTarray[index]))
{
cout<<"No alphabets allowed.\n\n";
cin.get();
exit(0);
}
}
if (atoi(TESTarray) > 1000000)
{
cout<<"Please do not enter numbers larger than 1,000,000. \n\n";
cin.get();
exit(0);
}
cout << "Number is OK";
}*/
{
if(oid[count3]= %||^||*||$||#||@||!||(ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')||~\\`||;||;||'||"||,||<||>||.||/||?)
cout<<"ERROR! YOU JUST TYPED A NON-INTEGER VALUE."<<endl;
cout<<"ENTER AN INTEGER PLEASE!"<<endl;
}//pre-if
for(int i=0;i<count3;i++)
{ if(oid[count3]==oid[i])
cout<<"ID NUMBER ALREADY EXISTS.";
goto G1;
}
++count3;
}
I have to do two things:
1) Check if the user enters anything else except a name in:
cout<<"ENTER YOUR NAME \n";
cout<<"Terminate with '$' "<<endl;
getline(cin,oname,'$');
I had this strategy:
{
if(! ((oname>='A'&&oname<='Z')||(oname>='a'&&oname<='z')) )
{cout<<"Enter a name please.Alphabets allowed only"<<endl;}
}
The problem is I cant compare a string with a character,rite? But if not character,then what to compare with a string in order to check that the user is entering a name or anything else.
2) I have to check if the user enters anything else except an integer in:
{
if(oid[count3]= %||^||*||$||#||@||!||(ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')||~\\`||;||;||'||"||,||<||>||.||/||?)
cout<<"ERROR! YOU JUST TYPED A NON-INTEGER VALUE."<<endl;
cout<<"ENTER AN INTEGER PLEASE!"<<endl;
}//p
The problem here is that I cant compare an int array with these symbols :S
How can i compare the integer with them; and how can i check if the user enters a name/character in place of integer?
Kindly help me out with this.
Thanks.