the quesiton is
Write a C++ program with a case structure. The program reads in a character from
the user, then translates it into a different character according to the following rules:
i. characters X, Y, Z will be translated to characters x, y, z respectively;
ii. the space character ' ' will be translated to underscore '_'
iii. digits 0, 1, 2, .., 9 will all be translated to the question mark '?'
iv. all other characters remain unchanged.
The program then displays the translated character.
BUT my problems are:
1. is that when you enter upper case Y or Z it stil converts to lower case 'x'
2. when you enter another characters besides capital X or Y or Z it still converts to a lower case x, y, z(i tried putting a not else if statement but doesnt work) AND this problems occurs also for option 2 below in the code
3. for the space character, it automatically converts itself without the user input but i want the user to enter it in
4. in the only number conversion, when you enter not numbers it will still convert :S
help please i have no idea wat to do now

im a beginner programmer
CODE
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
char ch;
int opselect;
cout << "Please select a number: ";
cout << "\n1 for characters X, Y, Z will be translated to characters x, y, z respectively\n";
cout << "\n2 for the space character ' ' will be translated to underscore '_'\n";
cout << "\n3 for digits 0, 1, 2, .., 9 will all be translated to the question mark '?'\n";
cout << "\n4 for all other characters\n";
cin >> opselect;
cout << "\nYou have selected option: " << opselect << endl;
switch (opselect)
{
case 1:
cout << "Please enter the character you want: ";
cin >> ch;
if (ch = 'X')
cout << "\nThe character you have entered is translated into x" << endl << "\n";
else if (ch = 'Y')
cout << "\nThe character you have entered is translated into y" << endl << "\n";
else if (ch = 'Z')
cout << "\nThe character you have entered is translated into z" << endl << "\n";
break;
case 2: //character 'space' condition
cout << "Please enter the character you want: ";
ch = cin.get();
if (ch = ' ')
cout << "\nThe character you have entered is translated into a '_' (underscore)"<< endl << "\n";
break;
case 3: //numbers
cout << "Please enter the character you want: ";
cin >> ch;
if (ch = '1')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '2')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '3')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '4')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '5')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '6')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '7')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '8')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '9')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = '0')
cout << "\nThe character you have entered is translated into a '?' (quesiton mark)" << endl << "\n";
else if (ch = 'X')
cout << "Invalid character. Please re-enter: ";
cin >> ch;
else if (ch = 'Y')
cout << "Invalid character. Please re-enter: ";
cin >> ch;
else if (ch = 'Z')
cout << "Invalid character. Please re-enter: ";
cin >> ch;
break;
case 4:
cout << "Please enter the character you want: ";
cin >> ch;
cout << "\nThe character you have entered is translated into a " << ch << endl << "\n";
break;
}
system("pause");
return 0;
}
This post has been edited by noob2007: 10 Apr, 2007 - 03:29 PM