2 Replies - 1497 Views - Last Post: 18 March 2013 - 04:11 AM Rate Topic: -----

#1 sacdeli  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-March 13

char C

Posted 17 March 2013 - 04:52 PM

I am trying to convert uppercase to lower case and vice versa, the program gives me error. This is the code so far:
include <iostream>
using namespace std;
int main()
{
    char ch;
    do
      {  cout <<"\n Enter a character: ";
         ch=getchar();
         if (ch>=65 && ch<=90)       
            ch = ch + 32;            
         else
             if (ch >=97 && ch <= 122)
             ch = ch -32;             
        putchar(ch);
      } while (ch!='0');

    return 0;
}


This post has been edited by macosxnerd101: 17 March 2013 - 04:54 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: char C

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2993
  • View blog
  • Posts: 10,342
  • Joined: 08-August 08

Re: char C

Posted 17 March 2013 - 06:15 PM

Try using #include in place of include.
Was This Post Helpful? 0
  • +
  • -

#3 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5833
  • View blog
  • Posts: 12,687
  • Joined: 16-October 07

Re: char C

Posted 18 March 2013 - 04:11 AM

Should work in an ASCII domain.

For clarity, though, I'd do something like:
ch = getchar();
if (ch>='A' && ch<='Z') {
	ch = (ch-'A') + 'a';
} else if (ch >='a' && ch <= 'z') {
	ch = (ch-'a') + 'A';
}
putchar(ch);



Of course, there are already functions for this: islower, isupper, tolower, toupper.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1