C++作业,不知道错在哪里(急)

来源:百度知道 编辑:UC知道 时间:2024/09/22 18:39:08
本人初学C++,水平实在太烂,请各位高手帮个忙,看看这段程序错在哪里~~
4、编写解密函数,将字符串的密文转换为明文。密文形成方法是字母A用其后第4个字符E代替,字母a用e代替。要求编写主函数加以测试。

#include <iostream>
using namespace std;
void jiemi(char str[])
{
str[100]="The key";
cout<<"加密后的字符串是:"<<str<<endl;
int i=0;
while(str[i]!=0)
{
if(str[i]>='A'&&str[i]<='V')
str[i]=str[i]+4;
else if(str[i]>='a'&&str[i]<='v')
str[i]=str[i]+4;
else if(str[i]>='W'&&str[i]<='Z')
str[i]=str[i]-'Z'+'A';
else if(str[i]>='w'&&str[i]<='z')
str[i]=str[i]-'z'+'a';
i++;
}
cout<<"加密前的字符串是:"<<str<<endl;
return 0;
}

#include <iostream>
using namespace std;
void jiemi(char str[])
{
//str[100]="The key"; // str[100]代表str的101个字符~~你却把字符串付值给了他~
str="The key";
cout<<"加密后的字符串是:"<<str<<endl;
int i=0;
while(str[i]!=0)
{
if(str[i]>='A'&&str[i]<='V')
str[i]=str[i]+4;
else if(str[i]>='a'&&str[i]<='v')
str[i]=str[i]+4;
else if(str[i]>='W'&&str[i]<='Z')
str[i]=str[i]-'Z'+'A';
else if(str[i]>='w'&&str[i]<='z')
str[i]=str[i]-'z'+'a';
i++;
}
cout<<"加密前的字符串是:"<<str<<endl;
// return 0; //函数是void的返回值~~你却返回了一个0;
}

正确程序如下:《不采用是你的错》
#include <iostream>
using namespace std;
void jiemi(char str[])
{