Piglatin输出将无法正常工作 [英] Piglatin output won't work correctly still

查看:230
本文介绍了Piglatin输出将无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>
using namespace std;
char firstLetter;
int pigLatin();
string word;
int wordFinder();
int firstVowel;
int x;
char vowel = ('a' && 'e' && 'i' && 'o' && 'u' && 'y' && 'A' && 'E' && 'I' && 'O' && 'U' && 'Y');
string engSentence;
char* letter = &engSentence[0];
bool vowelChecker (char c) // will check to see if there is a vowel
{
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'Y')
    {
        return true;
    }
    else
    {
        return false;
    }
}

int pigLatin()
{
    int lastLetter = word.length();
    firstLetter = word[0];


    if (vowelChecker(firstLetter)) //if the first letter of a word is a vowel...
    {
        cout << word << "way "; // print the word then way
    }
    else //if the first letter is not a vowel...
    {
        for (x = 1; x < lastLetter; x++) //in the loop of starting at the second letter and going to the last letter...
        {
            if (vowelChecker(x)) // check each letter to see if there is a vowel...
            {
                int firstVowel = x; //says that the first vowel is at point x
                break;
            }

        }
        string firstPortion = word.substr(0, firstVowel);
        string secondPortion = word.substr(firstVowel, lastLetter);
        cout << secondPortion << firstPortion << "ay";
        //above is stating that it will first print the part of the word from the first vowel to the last letter,
        //then it will print from the first letter to the first vowel and add 'ay' to the end

    }
    return 0;
}
int wordFinder() //will find words within a string
{
    char* letter = &engSentence[0];
    while ( *letter != '\0') //while the string isn't done...
    {
        if ( *letter == ' ' || *letter == '.' || *letter == ',' || *letter == '-' || *letter == '!' || *letter == '?') //if there is a space, comma or period...
        {
            pigLatin(); //run piglatin func
            cout << " "; // add a space before the next word
            word = "";  //sets the word back to empty

        }
        else
        {
            word += *letter; //adds letters to the word if no space comma or period is found.
        }
        letter++;
    }
    return 0;
}
int main()
{
    cout << "Please enter a sentence for me to translate: " << endl;
    cout << "**REMEMBER TO END SENTENCES WITH A PERIOD OR QUESTION MARK OR EXPLANATION MARK!**" << endl;

    getline(cin, engSentence); //will get the whole line entered
    wordFinder(); //runs wordfinder function
}

到目前为止,是第一个字母。 (if(vowelChecker(firstLetter)){cout<<<<way;})文本的这个部分...其他部分似乎没有在Piglatin函数中通过。另外,我收到一个警告,说firstVowel没有被使用,这将解释为什么我的程序运行不正确。不确定为什么,虽然...

So far, it will only work for if the vowel is the first letter. ( if (vowelChecker(firstLetter)) { cout << word << "way ";} ) this portion of the text... The other part seems to not being ran through in the Piglatin Function. Also I'm Getting a warning that says that firstVowel isn't being used, which would explain why my program isn't running correctly. Not sure why though...

推荐答案

if (vowelChecker(x)) // check each letter to see if there is a vowel...

这是传递循环变量x,不是那个位置的字符。你想要的是:

this is passing the loop variable x, not the character at that position. What you want is:

if (vowelChecker(word[x])) // check each letter to see if there is a vowel...

这篇关于Piglatin输出将无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆