|
write YOUR PROGRAMS IN A PROPER AND CONSISTENT CODING STYLE. 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.
here is my program:
#include <cstdlib> #include <iostream>
using namespace std;
int main() {
char ch, output; cout << "Enter A Character:"; ch = cin.get();
switch(ch) { case 'X': output = 'x'; break; case 'Y': output = 'y'; break; case 'Z': output = 'z'; break; case ' ': output = '_'; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': output = '?'; break; default: output = ch; } cout << "The translated character is: " << output << "\n\n"; system("PAUSE"); return EXIT_SUCCESS; }
now i need to make sure when i enter a number apart from 0-9, eg 99, it will display that number and not a '?'.
|