What should I do if I only want to display the sentence'Please enter only one char' once? should the user enter more than one character?
My program will repeat the above sentence countless times if enter a garbage like 'aksljdjlsadklsadklasdlkjaslkdjsakldjasljdlk'. I have read the faq but alas do not understand what is being said there.
Code:
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
char c[10];
cout<<"Please enter only a character\n";
cin.get(c, 10 , '\n');
cout<<strlen(c)<<endl;
if(strlen(c)>1)
{
cout<<"Please enter only one char\n";
}
cin.ignore();
cin.clear();
return 0;
}