WHAT AM I DOING WRONG?!! help!!

hi! im suposed to write a function that performs crypto "encryption" of a string. for example char 'a;, which is the first in the alphabet, becomes the last letter z, b becomes y b/c its the second-last letter, and so on. Uppercase and characters remain unchanged. in the main i need to cout<<Enter a string:, and print after encryption (after crypto:)
length of the input string is limited to 80 characters.
For example someone writes "aba" the output will be "zyz".
i wrote this and i dont get what im doing worng!! help please!!!!!


#include <iostream>
#include <string.h>
using namespace std;
void crypto(char string[80]){
int temp;
for(int i=0; i!='/0';i++){
if(string[i]>96||string[i]<123){
string[i]-'a'=temp;
string[i]='z'-temp;
cout<<string[i];
}
else
cout<<string[i];

}
}
int main(){
char strg[80];
char* s;
cout<<"Enter a string:"<<endl;
for (int i=0;i<80;i++)
cin>>strg[i];
cout<<"After crypto:"<<endl;
crypto(s);


return 0;
}












string[i]-'a'=temp;

What is this meant to do? Exactly what is supposed to have the value temp after this?
string[i]-'a'=temp;

Is this a typo, should be reversed.


Change the || in the if statement to &&.


You use include string despite never actually using strings. Perhaps the string[80] part is causing trouble.


You don't assign *s to anything.


Personally I'd start again and use string not char, e.g.

string input;
cout << "enter string" << endl;
getline(cin, input);

that way at least the user can choose how long the input can be rather than having to put in 80 characters every time.
Last edited on
Topic archived. No new replies allowed.