Skip to content

Instantly share code, notes, and snippets.

@CalvinRodo
Forked from anonymous/Piglatin
Created April 4, 2012 19:59
Show Gist options
  • Save CalvinRodo/2305149 to your computer and use it in GitHub Desktop.
Save CalvinRodo/2305149 to your computer and use it in GitHub Desktop.
Take word, decide if first letter is capitalized, a vowel, and if the word has any vowels.
#include <iostream>
#include <ctime>
#include <ctype.h>
using namespace std;
const int wordSIZE = 50;
void checkVowel(char word[], int size, bool &first_VOWEL, bool &first_CAP, bool &VOWEL );
int arrayLength(char[]);
void shiftLetters(char [], int);
void intro();
bool IsVowel(char c);
int main()
{
char init_word[wordSIZE];
char platin[4]={'w','a','y','\0'};
int count = 0, size;
bool first_VOWEL = NULL, first_CAP = NULL, VOWEL = NULL;
intro();
cout << "what is your word?...\n";
cin >> init_word;
size = arrayLength(init_word);
checkVowel(init_word, size, first_VOWEL, first_CAP, VOWEL);
cout << init_word << " " << size << endl;
if ( first_VOWEL == true ) { cout << "The first letter is a vowel!" << endl; }
else { cout << "First letter is not a vowel!" << endl; }
if ( first_CAP == true ) { cout << "The first letter is capital!" << endl; }
else { cout << "First letter is not capitalized!" << endl; }
if ( VOWEL == true ) { cout << "There are vowels in here!" << endl; }
else { cout << "There are no vowels. WTF." << endl; }
system("pause");
return 0;
}
void intro()
{
cout << "========PIG=LATIN=TRANSLATOR========\n"
<< "Translates any word into the ancient language of pig latin\n";
}
void checkVowel(char word[], int size, bool &first_VOWEL, bool &first_CAP, bool &VOWEL )
{
VOWEL = false;
//Guard Statement, no need to run if Char is empty.
if (size == 0){
return;
}
//Just need to check this once.
if ( isupper (word[0])){
first_CAP = true;
}
else{
first_CAP = false;
}
//Just need to check for a vowel and first vowel.
for ( int i = 0; i < size; i++ )
{
cout << word[0];
if (VOWEL = isVowel(word[i])){
if( i == 0) { first_VOWEL = true;}
}
return;
}
}
bool IsVowel(char c)
{
return strchr("aeiouyAEIOUY", c) != NULL;
}
int arrayLength(char word[])
{
int size=0, index=0;
while (word[index]!='\0')
{
size++;
index++;
}
return size;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment