如何获得显示结果?

时间:2019-05-08 01:24:23

标签: c++

我的结果是Arakbay Obamaway,而不是Arakbay OBAMAway,我在哪里做错了?

编写一个程序,该程序输入两个字符串变量,第一个和最后一个, 用户应输入每个人的姓名。第一, 将两个字符串都转换为小写。您的程序应 创建一个包含猪拉丁文全名的新字符串 首字母大写为名字和姓氏。 将单词转换为拉丁语的规则如下:

如果第一个字母是辅音,请将其移到末尾并在末尾添加“ ay”。 如果第一个字母是元音,请在末尾添加“ way”。

例如,如果用户输入“ Erin”作为名字,并且 姓氏为“ Jones”,则程序应创建一个新名称 带有“ Erinway Onesjay”文本的字符串并打印出来。

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
  char first[20];
  char last[20];
  bool existVowel;
  int length1=0;
  int length2=0;
  char vowel[5]={'a','e','i','o','u'};
  cout<<"Enter your first name: "<<endl;
  cin>>first;
  cout<<"Enter your last name: "<<endl;
  cin>>last;

  for(int i=0; first[i]; i++,length1++)
  {
    if((first[i]>='A')&&(first[i]<='Z'))
    {
      first[i]=first[i]+32;
    }
  }
  for(int i=0;last[i];i++,length2++)
  {
    if((last[i]>='A')&&(last[i]<='Z'))
    {
      last[i]=last[i]+32;
    }
  }
  existVowel=false;
  for(int i=0;i<5;i++)
  {
    if(first[0]==vowel[i])
    {
      strcat(first,"way");
      existVowel=true;
      break;
    }
    if(existVowel==false)
    {
      int i;
      char temp=first[0];
      for(i=0;first[i];i++)
      {
        first[i]=first[i+1];
        first[length1-1]=temp;
        first[length1]='\0';
        strcat(first,"ay");
      }
    existVowel=false;
    for(int i=0;i<5;i++)
    {
      if(last[0]==vowel[i])
      {
        strcat(last,"way");
        existVowel=true;
        break;
      }
      if(existVowel==false)
      {
        char temp=last[0];
      }
    }
    int i;
    for(i=0;first[i];i++)
    {
      last[i]=last[i+1];
      last[length2-1]=temp;
      last[length2]='\0';
      strcat(last,"ay");
    }
  first[0]=first[0]-32;
  last[0]=last[0]-32;
  cout <<"Your name in pig latin is: ";
  cout<<first<<" ";
  cout<<last<<endl;;
  return 0;
}

输入您的名字:Barak

输入您的姓氏:奥巴马

您在猪拉丁语中的名字是:Arakbay OBAMAway

0 个答案:

没有答案