Qbasicnews.com

Full Version: another nooby question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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$.
An excellent explanation, Zack! Big Grin
*****
Quote: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:
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.
Quote: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:
Quote: CHAR Stringname(numberofchars);

Don't you mean

CHAR Stringname[numberofchars];
Quote:
Rattrapmax6 Wrote:CHAR Stringname(numberofchars);

Don't you mean

CHAR Stringname[numberofchars];

Don't you mean

char Stringname[numberofchars];

lol
Quote:
TheDarkJay Wrote:
Rattrapmax6 Wrote: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;
Ah, the joys of syntax errors.... :roll: