Please need help!!!!!!!!!!!!!!!!!!!!!

How can i create a program that follows the ff. rules in Dev C++
5 letter input or more
have alternating consonants and vowels
display "accept" if the input followed the rules and "reject" otherwise

Thank you in advance for your help! it will be really appreciated. Sorry i'm very noob at programming.
Last edited on
closed account (ypLhURfi)
if this is not
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
35
36
#include <iostream>
using namespace std;
string password;
char letter;
int number;
int pass_to_ascii;
bool consonants=0;
bool vowels=0;
bool no_letters=0;
int main(){
	cin>>password;
	if(password.length()>=5){										//first condition                                           
		for(int number=0;number<=password.length();number++){		//pass the string to char
			letter=password[number];								
			pass_to_ascii=letter;									//pass the char to ascii
			if(pass_to_ascii>=65&&pass_to_ascii<=90){				//check consonants
				::consonants=1;
			}
			else if(pass_to_ascii>=97&&pass_to_ascii<=122)          //check vowels
			{
				::vowels=1;
			}
			else if(pass_to_ascii<65||(pass_to_ascii>90&&pass_to_ascii<97)||pass_to_ascii>122){							//check no letters
				::no_letters=1;
			}
			
		}
		
	}
	if(vowels==1&&consonants==1&&no_letters==0){			
				cout<<"accept";
			}
			else{
				cout<<"regect";
			}		
}
Last edited on
#include <cstdlib>
#include <iostream>

using namespace std;

bool vowel(char c){
char vowel[]="AEIOUaeiou";
for (int a=0;a<strlen(vowel);a++){
if (c==vowel[a]){
return true;
}
}
return false;
}
bool consonant (char c){
char consonant[]="BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz";
for (int a=0;a<strlen(consonant);a++){
if (c==consonant[a]){
return true;
}
}
return false;
}
int main (){
char array[0];
bool invalid;
int vowel=0,consonant=0,special=0;

invalid = false;

cout<<"Enter a Word:";
cin>>array;

cout<<endl;

for(int a=0;a<strlen(array);a++){
if(vowel(array[a])){
cout<<array[a]<<" - " <<"Vowel"<<endl;
vowel++;
}
else if (consonant(array[a])){
cout<<array[a]<<" _ " <<"Consonant"<<endl;
consonant++;
}
else{
cout<<array[a]<<" _ " <<"Special Character"<<endl;
special++;
}
}
cout<<endl;
if(consonant>=1){
cout<<consonant"Consonant found\n";
}
if(vowel>=1){
cout<<vowel"Vowel found\n";
}
if(special>=1){
cout<<special"Special Character\n";

for(int b=0; b<strlen(array)-1;b++)
if(vowel[b])==vowel(array[b+1]||strlen(array)<5||special>0){
cout<<"\nInput invalid \n";

system("PAUSE");
return EXIT_SUCCESS;
}

as of now this is all i got something is missing i can't figure it out please help
closed account (ypLhURfi)
I did not understand well your question.
I think that was what you wanted.
i'm sorry i forgot to say that another rule is added this is my project every twice a day my professor added another rule so when i did not pass the first 2 rules he will not check my program that is why. i will repeat the rules:
5 letter input or more
have alternating consonants and vowels
display "accept" if the input followed the rules and "reject" otherwise
and the added rule is i need to find how many consonants, vowels and special character in a word i enter
i try your code but when i enter derivative which is alternating word it display "reject" instead
"accept"?
closed account (ypLhURfi)
I do not know much about programming
I think now is fine
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
35
36
37
38
39
#include <iostream>
using namespace std;
string password;
char letter;
int number;
int pass_to_ascii;
bool consonants=0;
bool vowels=0;
bool no_letters=0;
int main(){
	cin>>password;
	if(password.length()>=5){										//first condition                                           
		for(int number=0;number<=password.length();number++){		//pass the string to char
			letter=password[number];								
			pass_to_ascii=letter;									//pass the char to ascii
			if(pass_to_ascii>=65&&pass_to_ascii<=90){				//check consonants
				::consonants=1;
			}
			else if(pass_to_ascii>=97&&pass_to_ascii<=122)          //check vowels
			{
				::vowels=1;
			}
			else if((pass_to_ascii> 31&&pass_to_ascii<65)||(pass_to_ascii>90&&pass_to_ascii<97)||pass_to_ascii>122){							//check no letters
				::no_letters=1;
			}						//me olvide de caracteres no imprimibles.
			
		}
		
	}
	cout<<vowels;
	cout<<consonants;
	cout<<no_letters;
	if(vowels==1&&consonants==1&&no_letters==0){			
				cout<<"accept";
			}
			else{
				cout<<"reject";
			}		
}
Last edited on
closed account (ypLhURfi)
no unprintable characters always come
Topic archived. No new replies allowed.