I need help with these programs.....

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Guest

I need help with these programs.....

Post by Guest » Fri Oct 28, 2005 3:33 pm

1) I need to write a program that finds all the vampire numbers and outputs it to a text file. Ex: 15 x 93 = 1395


2) I also need to write this prgram: Solve the following cryptogram.....
BP WPVBKPW PBLKE, LKP IKWQPKZ CBFM W XBKC FD FMKBQ DCP BLHQDXKLKPF. PDCWZWNE, LKP IKWQP CBFM W XBKC FD FMK WHHQDJWFBDP DS DFMKQE.

PLEASE PLEASE help me!!! IF youo know how to write these programs please tell me or if you know anything, im desperate.

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Fri Oct 28, 2005 4:12 pm

do your homework yourself.

ask your teacher. show us you made some effert and we will help, but we wont do your homework for you.
Image

shibby
Newbie
Posts: 5
Joined: Fri Oct 28, 2005 3:25 pm

Post by shibby » Fri Oct 28, 2005 4:20 pm

I dont want you to do it for me. I just need some tips, like where to start or an outline. Maybe what loop to use....anything.

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Fri Oct 28, 2005 6:00 pm

Your teacher is there to help you.

First one is accomplished the easiest way with string conversion functions..

Second one is impossible without knowing the algorithm used to encrypt..
I have left this dump.

Guest

Post by Guest » Sat Oct 29, 2005 9:10 am

My teacher wont help us, she acts like a hard ass. And the tells you nothing. and whats a string conversion function?

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Sat Oct 29, 2005 9:46 am

If the teacher is bad, go to the principal and explain the situation. if the teacher is as bad as you claim others feel the same so you should have no problems in either getting the teacher a warning or making her epxlain stuff.

String conversion functions are functions that work on strings and convert them in one way or another.. such as: STR$(), LEFT$(), RIGHT$(), MID$(), VAL()
I have left this dump.

User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm
Contact:

Post by Zamaster » Sat Oct 29, 2005 11:20 am

Hey, wait a sec! It is possible to decifer cryptograms w/o knowing the original crypting algorithm. It wouldnt be easy though. You first need a list of all the words in the english language. Then you have the program solve it just the way you would. I dont feel like explaining the logic. And as for the wompire numbes... It ain't THAT hard. Think about what your doing. Go through 2 sets of numbers, multiply em,' check to see if they create a number contating the characters in the original 2.
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

Guest

Post by Guest » Sat Oct 29, 2005 11:38 am

For the vampire numbers what loop would i need to do? DO while....Do until.....For/Next statement.......Im sorry im not good at programming it's my first year and i have a C in it.

User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened » Sat Oct 29, 2005 12:09 pm

Zamaster: I just realized... your signature has backslashes (//), they should be regular slashes (\\) if you want it to be like DOS's filesystem.

And to the original poster: think about the problem you're trying to solve. Do you know how many times you're going to have to run the loop? If so, you'll want to use a For...Next loop. If you don't know, or you want to run it indefinately, use a do loop.
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Sat Oct 29, 2005 12:29 pm

This is a thing that my old programming book said:

1>Does it run a certain amount of times? t = for loop f = 2
2>Does it need to run at least once? t = do loop f = while loop

I think thats it, I couldnt find it...
Image

Guest

Post by Guest » Sat Oct 29, 2005 1:11 pm

Here's is what the problem says: THE CHALLENGE...Write a program,as short as possible, that finds every vampire number and outputs it toa text file.


-OK! I think i got it tell me if i do.... here is what i wrote

CLS : FOR q = 10 TO 99
FOR p = 10 TO 99

c$ = LTRIM$(RTRIM$(STR$(q * p))) 'candidate product in string

' "parse"
u$ = LEFT$(LTRIM$(RTRIM$(STR$(q))), 1) 'factor 1 byte 1
d$ = RIGHT$(LTRIM$(RTRIM$(STR$(q))), 1) 'factor 1 byte 2
t$ = LEFT$(LTRIM$(RTRIM$(STR$(p))), 1) 'factor 2 byte 1
q$ = RIGHT$(LTRIM$(RTRIM$(STR$(p))), 1) 'factor 2 byte 2

bc$ = ""

IF q$ + t$ + d$ + u$ = c$ OR q$ + t$ + u$ + d$ = c$ OR q$ + d$ + t$ + u$ = c$ THEN bc$ = c$
IF q$ + d$ + u$ + t$ = c$ OR q$ + u$ + t$ + d$ = c$ OR q$ + u$ + d$ + t$ = c$ THEN bc$ = c$
IF t$ + q$ + d$ + u$ = c$ OR t$ + q$ + u$ + d$ = c$ OR t$ + d$ + q$ + u$ = c$ THEN bc$ = c$
IF t$ + d$ + u$ + q$ = c$ OR t$ + u$ + q$ + d$ = c$ OR t$ + u$ + d$ + q$ = c$ THEN bc$ = c$
IF d$ + q$ + t$ + u$ = c$ OR d$ + q$ + u$ + t$ = c$ OR d$ + t$ + q$ + u$ = c$ THEN bc$ = c$
IF d$ + t$ + u$ + q$ = c$ OR d$ + u$ + q$ + t$ = c$ OR d$ + u$ + t$ + q$ = c$ THEN bc$ = c$
IF u$ + q$ + t$ + d$ = c$ OR u$ + q$ + d$ + t$ = c$ OR u$ + t$ + q$ + d$ = c$ THEN bc$ = c$
IF u$ + t$ + d$ + q$ = c$ OR u$ + d$ + q$ + t$ = c$ OR u$ + d$ + t$ + q$ = c$ THEN bc$ = c$

IF bc$ <> "" AND INSTR(dupe$, bc$) = 0 THEN dupe$ = dupe$ + bc$ + SPACE$(1): PRINT q; "x"; p; "= "; bc$

NEXT p
NEXT q

User avatar
Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm

Post by Kyle » Sat Oct 29, 2005 4:45 pm

The awakened: \\ are backslashes, // are forward slashes :D

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Sat Oct 29, 2005 4:55 pm

I did not understand your code completly (as in, I know it but it could be better). How about telling us what each var is? Because I think I know a way that INSTR can help you out here... thats a good little function there it is...
Image

User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened » Sat Oct 29, 2005 5:03 pm

Kylemc wrote:The awakened: \\ are backslashes, // are forward slashes :D
Well, whatever. :)
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."

User avatar
Kyle
Veteran
Posts: 107
Joined: Thu Apr 14, 2005 2:41 pm

Post by Kyle » Sat Oct 29, 2005 5:08 pm

Well, your code is reasonably ugly, but it seems to work fine.

Guest
Veteran
Posts: 128
Joined: Sun Aug 14, 2005 8:33 pm
Location: Forest Lake, MN
Contact:

Post by Guest » Sat Oct 29, 2005 5:23 pm

This is BBCode, remove the asterisks to input it.
[*code]Input Code Here[*/code]
The result:

Code: Select all

Input code here
in a code statement, you can also space as much as you want, so your code will also gain legibility

Guest

Post by Guest » Sat Oct 29, 2005 6:24 pm

Well how could i make my program shorter and more legable???? Remember ima noobie so i wont understand most the stuff you are talking about unless you explain it. By the way thank you for the help.

User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm
Contact:

Post by Zamaster » Sat Oct 29, 2005 7:14 pm

Yuck, I lost my appetite when I saw that code, just kidding. But, it could be a bit better.

Code: Select all

DECLARE FUNCTION num$ (nm&)

FOR mul1% = 1 TO 400
FOR mul2% = 1 TO 400

mstr$ = num$(CLNG(mul1%) * CLNG(mul2%))
nstr$ = mstr$
m1$ = num$(CLNG(mul1%)): m2$ = num$(CLNG(mul2%))
f% = 0

FOR i% = 1 TO LEN(m1$)
test% = INSTR(nstr$, MID$(m1$, i%, 1))
IF test% <> 0 THEN
MID$(nstr$, test%, 1) = SPACE$(1)
f% = f% + 1
ELSE
EXIT FOR
END IF
NEXT i%

FOR i% = 1 TO LEN(m2$)
test% = INSTR(nstr$, MID$(m2$, i%, 1))
IF test% <> 0 THEN
MID$(nstr$, test%, 1) = SPACE$(1)
f% = f% + 1
ELSE
EXIT FOR
END IF
NEXT i%

IF f% = LEN(m1$) + LEN(m2$) THEN
PRINT mstr$+","+m1$+","+m2$
END IF

NEXT mul2%
NEXT mul1%

FUNCTION num$ (nm&)
num$ = RIGHT$(STR$(nm&), LEN(STR$(nm&)) - 1)
END FUNCTION
At least I like this code better. Everybody else might say otherwise. :P
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

Guest
Veteran
Posts: 128
Joined: Sun Aug 14, 2005 8:33 pm
Location: Forest Lake, MN
Contact:

Post by Guest » Sat Oct 29, 2005 7:23 pm

Anonymous wrote:Well how could i make my program shorter and more legable???? Remember ima noobie so i wont understand most the stuff you are talking about unless you explain it. By the way thank you for the help.
By spacing on do..loops, for..nexts, while..wends, and if..then..end if statements as well as subs and functions. If you were a C programmer at one point, you would know the importance of tabbing & spacing for example:
Which is more readable and understandable?

Code: Select all

CLS
SCREEN 18

DO
    PSET(x, y), RND * 15
    x = x + 1
    y = y + 1
LOOP

Code: Select all

CLS
SCREEN 18

DO
PSET(x,y), rnd * 15
x = x + 1
y = y + 1
LOOP

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Sun Oct 30, 2005 12:52 pm

yeah, i do that all the time, even before I started learning C++. it really does help beutify the code.... unless if you used it the way they did in the windows x code... that was HORRIBLE!
Image

Post Reply