Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 11th, 2006, 4:34 PM   #1
skoob
Newbie
 
skoob's Avatar
 
Join Date: May 2006
Location: AZ
Posts: 8
Rep Power: 0 skoob is on a distinguished road
Send a message via MSN to skoob Send a message via Yahoo to skoob
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
skoob is offline   Reply With Quote
Old May 11th, 2006, 4:44 PM   #2
hervens48
Hobbyist Programmer
 
Join Date: Apr 2006
Location: Montreal, Canada
Posts: 107
Rep Power: 3 hervens48 is on a distinguished road
Send a message via AIM to hervens48 Send a message via MSN to hervens48
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
hervens48 is offline   Reply With Quote
Old May 11th, 2006, 4:45 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old May 11th, 2006, 4:49 PM   #4
skoob
Newbie
 
skoob's Avatar
 
Join Date: May 2006
Location: AZ
Posts: 8
Rep Power: 0 skoob is on a distinguished road
Send a message via MSN to skoob Send a message via Yahoo to skoob
haaaaaaaa thank you
skoob is offline   Reply With Quote
Old May 11th, 2006, 5:01 PM   #5
mrynit
Hobbyist Programmer
 
mrynit's Avatar
 
Join Date: Mar 2006
Location: WA, USA
Posts: 343
Rep Power: 3 mrynit is on a distinguished road
Send a message via AIM to mrynit Send a message via MSN to mrynit Send a message via Yahoo to mrynit Send a message via Skype™ to mrynit
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
mrynit is offline   Reply With Quote
Old May 11th, 2006, 5:19 PM   #6
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
~Code tags added for readability
__________________
&quot;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.&quot; - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old May 11th, 2006, 5:21 PM   #7
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old May 11th, 2006, 5:27 PM   #8
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
Quote:
Originally Posted by mrynit
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
endl has more overhead, which was discussed somewhere (I'm too lazy to search hard) but I found this other comparison:
Quote:
Originally Posted by DaWei
'\n' is the code for a newline. It's used for a new line. "Endl" implies a newline followed by a flush of the buffer. Not precisely the same thing. You can't check content for an "endl", of course, you have to check for the character.
Jimbo is offline   Reply With Quote
Old May 11th, 2006, 10:45 PM   #9
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,194
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by mrynit
style note: \n reminds me of perl.
Where do you think Perl got the syntax? :)
Quote:
Originally Posted by mrynit
<< 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
Actually, while using << endl may be more 'C++ like', there's nothing C like about it (unless both endl and the operator's lvalue are integral types, specifically unsigned, at least for most compilers).
__________________
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
lectricpharaoh is online now   Reply With Quote
Old May 12th, 2006, 1:53 AM   #10
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC