简体   繁体   中英

C++ pig latin translator

im writing a program in C++ that translates a sentence into pig latin, only by taking the first letter of the word and taking it to the end then and adding "ay" example "hello world" becomes "ellohay orldway" but its not working, ive tried several different ways none are working, at this point im about to give up, please can some one help me do this right.

#include "stdafx.h"

#include <iostream>
#include <string>
using namespace std;

void seperator(char []);

int main()
{
    string input;
    const int SIZE = 40;
    char sent[SIZE];

    cout << " enter sentence " << endl;
    cin >> input;
    cin.getline(sent, SIZE);
    seperator(sent);
    cout << input << endl;


    system ("pause");
    return 0;
}

void seperator(char input[])
{
    int count = 0;
    char x;
    while (input[count] != '\0')
        count++;
    if (isalpha(input[count]))
        x =input[count];
    if (input[count] == ' ')
        input[count] = (x + ' ');
    if (input[count] == ' ')
        input[count] = 'ay';


}

Your cin >> input; is only getting the string up till the first whitespace, so the space between hello and world .

That's why it appears to be deleting everything but the first word, you should use something like std::getline (std::cin,input);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM