Hi there, I have to make a program for my C++ class and it's due tomorrow. Here is what the code should do:
Create a program that allows the user to enter a word. The program should display the word in pig latin form.Here are the conversions:
a.) When the word begins with a vowel(A, E, I, O, or U), add the string "-way" to the end of the word. Ex: ant becomes ant-way.
b.) When the word doesn't begin with a vowel, first add a dash to the end of the word. Then continue moving the first character in the word to the end of the word until the first letter is A, E, I, O, U, or Y. Then add the string "ay" to the end of the word. Ex: Chair becomes air-Chay.
c.) When the word doesn't contain the letter A, E, I, O, or Y, add the string "-way"to the end of the word. Ex: 56 becomes 56-way.
Similar to part A.
Here 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
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string Word;
string NewWord;
string NewWord2;
cout << "Enter a word: ";
cin >> Word;
for(int x = 0; x <= Word.length(); x++)
{
if(Word.substr(x, 1) == "a" || Word.substr(x, 1) == "e" || Word.substr(x, 1) == "i" || Word.substr(x, 1) == "o" || Word.substr(x, 1) == "u")
{
NewWord = Word + "-way";
cout << NewWord << endl;
}
}
for(int y = Word.length(); y = 0; y++)
{
if(Word.substr(1, y) != "a" || Word.substr(1, y) != "e" || Word.substr(1, y) != "i" || Word.substr(1, y) != "o" || Word.substr(1, y) != "u")
{
NewWord2 = Word + "ay";
cout << "-" << NewWord2 << endl;
}
}
system("PAUSE");
return 0;
}
|