Qbasicnews.com
April 08, 2020, 12:38:33 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: another nooby question  (Read 2613 times)
madefromheaven
New Member

Posts: 3


« on: February 08, 2006, 05:55:31 PM »

Write a program that prompts the user to enter a sentence and then switche all lowercase letters to capitals and all uppercase letters to lowercase.  Use the ASC function to know which letters to switch.  

how to do use the ASC function to solve this question?
Logged
Zack
*/-\*
*****
Posts: 3974



WWW
« Reply #1 on: February 08, 2006, 06:03:07 PM »

All characters (including letters) have what's called an ASCII code. An ASCII code is a number from 0 to 255. Lowercase and uppercase letters have different ones. The ASC(c$) function returns the ASCII code for c$. ASCII codes 65 through 90 (inclusive) are all the uppercase letters in alphabetical order. Codes 97 through 122 (inclusive) are all the lowercase letters. So, it follows logically that to change a lowercase letter to an uppercase one, subtract 32. Add 32 to change an uppercase letter to a lowercase one.
You'll need the CHR$(n) function as well, which returns the character represented by ASCII code n.

Of course using ASC to do that is ridiculous because QB already has two functions for doing just what you need. (LCASE$(c$) and UCASE$(c$) return the lowercase and uppercase (respectively) equivalents of c$.
Logged

f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Moneo
Na_th_an
*****
Posts: 1971


« Reply #2 on: February 08, 2006, 10:36:34 PM »

An excellent explanation, Zack! Cheesy
*****
Logged
Rattrapmax6
__/--\__
*****
Posts: 2577



WWW
« Reply #3 on: February 09, 2006, 12:08:53 AM »

Quote from: "Zack"
Of course using ASC to do that is ridiculous because QB already has two functions for doing just what you need. (LCASE$(c$) and UCASE$(c$) return the lowercase and uppercase (respectively) equivalents of c$.

That's because it's obviously home work (as the last question proved to be),. a challenge to stimulate creative problem solving.... on their own....  :roll:
Logged

Kevin (x.t.r.GRAPHICS)

RyanKelly
Forum Regular
**
Posts: 109



WWW
« Reply #4 on: February 09, 2006, 12:26:15 AM »

That actually sounds like a great homework assignment.  The problem breaks down into a number of sub-problems.  The solution sort of interlaces the solution of each.

1) Scan through a string one character at a time.
2) Classify each character as either uppercase, lowercase, or neither (numerical,punctuation or white space.)
3) Build a string one character at a time.

I remember when I first picked up C and discovered that something like this, which is so straight forward in BASIC with the ability to concatenate strings with the "+" operator and the built in string memory handling, was such a pain in C.

Then, of course, one finds out that this particular problem can be solved much more elgantly in C when you treat the string as an array, which in BASIC was a pain, until Powerbasic and Turbobasic introduced pointers.
Logged
Rattrapmax6
__/--\__
*****
Posts: 2577



WWW
« Reply #5 on: February 10, 2006, 03:13:42 PM »

Quote from: "RyanKelly"
Then, of course, one finds out that this particular problem can be solved much more elgantly in C when you treat the string as an array, which in BASIC was a pain, until Powerbasic and Turbobasic introduced pointers.

It's not a pain in Basic,. you just got to know what to do..  :wink: .... BTW, you left FreeBasic out of that list,. It has pointers,. it also has zstring which is much like C's CHAR Stringname(numberofchars);....  :roll:
Logged

Kevin (x.t.r.GRAPHICS)

TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #6 on: February 10, 2006, 04:20:06 PM »

Quote from: "Rattrapmax6"
CHAR Stringname(numberofchars);


Don't you mean

CHAR Stringname[numberofchars];
Logged

url=http://www.sloganizer.net/en/][/url]
yetifoot
Ancient Guru
****
Posts: 575



« Reply #7 on: February 10, 2006, 09:08:01 PM »

Quote from: "TheDarkJay"
Quote from: "Rattrapmax6"
CHAR Stringname(numberofchars);


Don't you mean

CHAR Stringname[numberofchars];


Don't you mean

char Stringname[numberofchars];

lol
Logged

EVEN MEN OF STEEL RUST.
thegrogen
Ancient QBer
****
Posts: 444



« Reply #8 on: February 10, 2006, 09:46:01 PM »

Quote from: "yetifoot"
Quote from: "TheDarkJay"
Quote from: "Rattrapmax6"
CHAR Stringname(numberofchars);


Don't you mean

CHAR Stringname[numberofchars];


Don't you mean

char Stringname[numberofchars];

lol


You forgot this:

Code:

char *stringname;


This one is by far the best:
Code:

std::string stringname;
Logged

.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Rattrapmax6
__/--\__
*****
Posts: 2577



WWW
« Reply #9 on: February 10, 2006, 10:14:05 PM »

Ah, the joys of syntax errors....  :roll:
Logged

Kevin (x.t.r.GRAPHICS)

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!