Welcome to Dream.In.Code
Become a C++ Expert!

Join 136,930 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,836 people online right now. Registration is fast and FREE... Join Now!




Create a C++ program with case structure that read a char from user an

 
Reply to this topicStart new topic

Create a C++ program with case structure that read a char from user an

JGuybrush
1 Apr, 2008 - 06:03 AM
Post #1

New D.I.C Head
*

Joined: 1 Apr, 2008
Posts: 1

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;
}
User is offlineProfile CardPM
+Quote Post

schnalf
RE: Create A C++ Program With Case Structure That Read A Char From User An
1 Apr, 2008 - 06:38 AM
Post #2

D.I.C Head
**

Joined: 9 Feb, 2008
Posts: 124



Thanked: 2 times
My Contributions
hi,
you can convert an upper case char to a lower case char through adding to the char 32 or in the other way you have to sub 32, then you will manipulate the meaning in the ascii code.


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 10:35PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month