|
I was ask to create a C++ program in case structure that must read a character from the user and display it translation according to the following rule:
i) Characters A, E, I, O, U will be translate to character a, e, i, o, u ii) The space character will be translate to underscore '_' iii) Digits 0,1,2,3...9 will be translate to '#' iv) all other character will remain unchange. ------------------------------------------------------------------------------- I only manage to do the first option where a uppercase character get converted to lowercase but it doesn't seem to work properly. The program does run but can't seem to get the conversion to actually work. Can you show me how I can correct this problem?
#include <cstdlib> #include <iostream>
using namespace std;
int main(int argc, char *argv[]) { char ch; cout << "Please enter a character:"; ch=cin.get(); if (ch >= 'A' && ch <= 'Z') cout << "1st char has code " << unsigned(ch) << " and is \"" << ch << "\"\n"; else if (ch >='a' && ch <='z') cout << "2nd char has code " << unsigned(ch) << " and is \"" << ch << "\"\n"; system("PAUSE"); return 0; } -------------------------------------------------------------------------- this is the third option with the digit, the program seem not to be able to read the condition properly. the program does run but it doesn't produce the right result. Can you direct me in the right way.
#include <cstdlib> #include <iostream>
using namespace std;
int main(int argc, char *argv[]) { int num; cout << "Enter an integer: "; cin >> num; if (num >= 0 && input <= 9) { cout << "Your number is." << input << endl; } else { cout << "Your number is." << input << endl; } system("PAUSE"); return EXIT_SUCCESS; }
|