![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
program
hi can some one help me with this code, i don't know what is wrong.
// charchang.cpp
#include <iostream.h>
#include <ctype.h>
int main()
{
char a;
do
{
cout << "Enter a upper or lowercase character\n";
cin >> a;
if( ! isalpha(a))
{
cout << "The character must be a letter\n";
}
} while( ! isalpha(a));
if(islower(a))
{
cout << "The character " << a << " is lower case\n";
cout << a << " converted to " << "Uppercase ";
a = toupper(a);
cout << a;
}
else
{
cout << "The character " << a << " is Uppercase\n";
cout << a << " converted to " << "lowercase is ";
a = tolower(a);
cout << a
}
return 0;
}Last edited by Mjordan2nd; May 11th, 2006 at 5:19 PM. Reason: Code tags |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
i found the answer.
U forgot the semi colom ( ; ) after cout<<a its on the last line before return 0 then it should work. I tested it on my dev c++ compiler |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Please read the forum's rules/FAQ. Pay particular attention to the mention of "code tags". They preserve your indentation and formatting. Be polite, play nice, there's plenty of help.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Newbie
|
haaaaaaaa thank you
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
style note: \n reminds me of perl. << endl; to me is more tradional C/C++ like.
<< endl; sticks out more than having a blob of text then a \n. my two cents
__________________
i dont know much about programming but i try to help |
|
|
|
|
|
#6 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
~Code tags added for readability
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#7 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
You are using deprecated headers. Try something like:
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char a;
do
{
cout << "Enter a upper or lowercase character: ";
cin >> a;
if(!isalpha(a))
{
cout << "The character must be a letter" << endl;
}
}
while(!isalpha(a));
if(islower(a))
{
cout << "The character '" << a << "' is lowercase" << endl;
cout << a << " converted to " << "uppercase is" << (char)toupper(a) << endl;
}
else
{
cout << "The character '" << a << "' is uppercase" << endl;
cout << a << " converted to " << "lowercase is " << (char)tolower(a) << endl;
}
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#8 | ||
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3
![]() |
Quote:
Quote:
|
||
|
|
|
|
|
#9 | ||
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,194
Rep Power: 5
![]() |
Quote:
Quote:
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
||
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
you've just discovered the number one error in programming.
:p
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|