Need some help

I am working on a program that asks the user for a first name but the characters have to be all alphabetic characters. I get it to run almost correct but when i input a plain name without special characters or numbers i get my output multiple times.

here is my coding

#include <iostream>
#include <cstring>
using namespace std;

int main
{
string name;

cout << "What's your first name?" << endl;
cin >> name;

for (int x = 0; x < name.length(); x++)\
{
if (name[x] >= 65 && name[x] <= 90 || name[x] >=97 && name[x] <= 122)
{
cout << "Valid name." << endl;
}
else
{
cout << "Your name cannot contain: " << name[x] << endl;
cout << "Invalid name." << endl;
}
}

plus i just found another bug. it outputs the entire input with the invalid character instead of just the invalid character along with outputing valid name for the number of times there are characters.
if you can run this I am God ;)
how would you suggest i do it properly
first you need a "main" function to start the program
i have one i just forgot to write in here the ()
ok post your corrected code use tags (on the right <>)
Last edited on
This is my code

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
string name;

cout << "What's your first name?" << endl;
cin >> name;

for (int x = 0; x < name.length(); x++)
{
if (name[x] >= 65 && name[x] <= 90 || name[x] >=97 && name[x] <= 122)
{
cout << "Valid name." << endl;
}
else
{
cout << "Your name cannot contain: " << name[x] << endl;
cout << "Invalid name." << endl;
}
}

}
Topic archived. No new replies allowed.