ok i am almost done with this program, but i am stuck, well sort of. i need help with compressing, i guess you can say, the program.
examples of the program i want to finish:
ex1: Julio.
Valid name
ex2: julio123
your name cannot contain: 1
your name cannot contain: 2
your name cannot contain: 3
Invalid name
and as of now i have done everything, but right now my program outputs everything like. J is a valid name, u is a valid name etc. and when it encounters a 1, invalid name, your name cannot contain: 1. but it will output the rest of the letters. i want it to not output the "valid name" for each of the alphabetical letters, but just output what is wrong with the name. i think i am just babbling at this point. the examples should tell you what must be done.
and this is my code so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char first_name[100];
cout << "What's your first name?" << endl;
cin >> first_name;
for(int i = 0; i < first_name[i] != '\0'; i++)
{
if (first_name[i] >= 'A' && first_name[i] <= 'Z' || first_name[i] >= 'a' && first_name[i] <= 'z')
{
cout << "Valid name." << endl;
if (first_name[i] <= '0' && first_name[i] >= '64' || first_name[i] <= '91' && first_name[i] >= '96' || first_name[i] <= '123' && first_name[i] >= '127')
{
cout << "invalid name." << endl;
}
}
else
{
cout << "Your name cannot contain: " << first_name[i] << endl;
cout << "Invalid name." << endl;
}
}
//cout << "Valid name." << endl; <--Ignore.
}
|