When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
13 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
You're doing basically nothing that's in that assignment
It asks you to write a program that translates a single character, not a string. And it says you should use a switch statement to translate the letters, not some ascii values math.
#include <iostream>
using namespace std;
int main()
{
char ch;
cout << "Enter a letter (A - Z): ";
cin >> ch;
if (ch >= 'a' && ch <= 'z') {
ch = ch - 'a' + 'A';
}
cout << "ROT13 Caesar Cipher for " << ch << " - > ";
switch (ch) {
case 'A':
cout << 'N' << endl;
break;
case 'B':
cout << 'O' << endl;
break;
case 'C':
cout << 'P' << endl;
break;
case 'D':
cout << 'Q' << endl;
break;
case 'E':
cout << 'R' << endl;
break;
case 'F':
cout << 'S' << endl;
break;
case 'G':
cout << 'T' << endl;
break;
case 'H':
cout << 'U' << endl;
break;
case 'I':
cout << 'V' << endl;
break;
case 'J':
cout << 'W' << endl;
break;
case 'K':
cout << 'X' << endl;
break;
case 'L':
cout << 'Y' << endl;
break;
case 'M':
cout << 'Z' << endl;
break;
case 'N':
cout << 'A' << endl;
break;
case 'O':
cout << 'B' << endl;
break;
case 'P':
cout << 'C' << endl;
break;
case 'Q':
cout << 'D' << endl;
break;
case 'R':
cout << 'E' << endl;
break;
case 'S':
cout << 'F' << endl;
break;
case 'T':
cout << 'G' << endl;
break;
case 'U':
cout << 'H' << endl;
break;
case 'V':
cout << 'I' << endl;
break;
case 'W':
cout << 'J' << endl;
break;
case 'X':
cout << 'K' << endl;
break;
case 'Y':
cout << 'L' << endl;
break;
case 'Z':
cout << 'M' << endl;
break;
}
return 0;
}
I believe I change it to a swtich now, but still don't know how to include an error incase they don't insert a letter
Just use a default case to print the error
The assignment also said nothing about converting lowercase to uppercase, no idea why you're adding all these things
int main()
{
char input, ouput;
// request input char
switch (input)
{
case 'A':
output = 'N';
break;
// .. etc
default:
// print error message
return 0;
}
// print conversion message
return 0;
}
That should really be all you need to do
Ohhh okay
@versed narwhal
Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.
!solved