the name can consist of letters spces a single quotation mark and a single hyphen. if there is a illegal character the program will ask to re enter name.
only new to coding so pleas bare with me. not really sure how to go about using the while loop and have been trying a few things and this is the best I came up with,
You can only use isalpha one character at a time. Since it seems you're trying to figure out loops, try using it in a loop over the whole line, for example I've used a for loop here:
ok have been at it all day and ive changed it to a do while but its still not working, and when I input a wrong name it repeatedly couts" is not a valid name" "please enter your name" as its suppose to but not so many times.
usingnamespace std;
#include <conio.h>
#include <iostream>
//#include <string>
int main(){
char name;
bool valid;
do{
valid = true;
cout<<"Please enter your name: ";
cin>>name;
if (!isalpha(name))
valid=false;
if (name==' ')
valid=true;
if (name=='-')
valid=true;
if (name==' '*2)
valid=false;
if (name=='a'*2)
valid=false;
if (valid)
cout<<name<<" is a valid name";
if(!valid) cout<<"sorry that is a incorrect name:\n";
}
while (!valid);
//getch();
return 0;
}