QBASIC help, NEWBIE here!!!

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

Post Reply
moto1978
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 6:27 pm

QBASIC help, NEWBIE here!!!

Post by moto1978 »

Alright, I know one of your threads says you won't do homework..lol

Sucks but it is what it is. I can't get this to save my life...I'm never gonna use it but I have to take it for my Web Design degree.

I've done ok so far...midterm is tonight which I'm sure I will FAIL...so as long as I can get the homework done I just might pass which is all I care aboutat this point

So any help would be greatly appreciated.

We usually have examples where I can start off from but I don't have one for this assignment so what I have done so far I'm sure is 110% WRONG!! lol

Anyone wanna help? I'm sure most of you can do this in 5 minutes. I have now been working on this for 4 hours today....I should've searched for a forum back in January

Here is the assignment
Write a program to compute your checking account balance for one month's
transactions.

INPUT: The first input should be the bank balance from the previous month. Then
depoists, checks, or service charges will be entered at the keyboard. The user
should be prompted to enter D,C,S,or E (for Deposit, Check, Service charge, or End),
and the amount of the transaction.

OUTPUT: Print a statement with a title and column headings , showing the beginning
balance, each transaction as it is applied, and a current balance.
(Note this will be displayed on the Monitor so that the input prompts and responses
and the printing will be intermixed - Not always pretty.)

PROCESSING: Add deposits to the balance and subtract checks and service charges.

TEST DATA:
Beginning balance $20.05
Check 15.00
Deposit 50.50
Check 45.57
Check 5.00
Deposit 60.00
Service charge 6.00
End

Notes: Please note that the monitor will not be just the output or the input as
they will be intermixed.

There will be three variables to take care of the inputs and numbers.
There my be other variables to hold the print formats. Try to use formated printing.

***************************
This is what I have so far
ok, this is what I started with...of course going off of another assignment. I'm lost in the calculate answer field

I know how to add and subtract but don't know how to start with a certain balance or write the code to say if it says deposit add and if it's a check subtract.

would it be somthing like
if Check then
not sure how to say subtract from the a running balance
then
if Deposit then
same thing

will it know to tie the word Check to the data???
CLS
GOSUB SetUpConstants
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB CalculateAnswer
GOSUB PrintDetail
END

REM SET UP CONSTANTS
SetUpConstants:
LET H$ = " Bank Balance"
LET H1$ = " Beginning Balance"
LET H2$ = " Transaction"
LET D1$ = "\ \ ### ## ###"
LET TOTAL$ = " Current Balance #### ### ###"
RETURN


PrintHeadings:
PRINT
PRINT H$
PRINT
PRINT H1$
PRINT
PRINT H2$
PRINT
RETURN


ProcessDetail:
GOSUB ReadData
DO WHILE UCASE$(Nam$) <> "END"
GOSUB CalculateAnswer
GOSUB PrintDetail
GOSUB ReadData
LOOP
RETURN

CalculateAnswer:



RETURN



ReadData:
READ Trans, Amount
DATA Check, 15.00
DATA Deposit, 50.50
DATA Check, 45.57
DATA Check, 5.00
DATA Deposit, 60.00
DATA Service Charge, 6.00
DATA END, 0, 0
RETURN


PrintDetail:
PRINT USING
RETURN
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You are heading in the wrong direction with DATA. The assignment clearly says that keyboard INPUT will be used. The first entry would be the monthly balance.

You want to make a loop with an initial key press to tell the program what you want to do so that the value can be worked with:

Code: Select all

DO
CLS
GOSUB PrintMenu 'this sub prints the options to the screen
K$ = UCASE$(INPUT$(1))  'this tells the program what to do 
INPUT "Amount of transaction", amount

SELECT CASE K$

CASE "C": balance = balance - amount
CASE "D": balance = balance + amount

END SELECT

PRINT "Balance ="; balance

LOOP UNTIL K$ = "Q"

Your assignment does not have to look pretty on the screen...a lot of transactions may scroll the screen without CLS.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
moto1978
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 6:27 pm

Post by moto1978 »

Well ur response was greek to me...lol

thanks anyway
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Run this code:

Code: Select all

DO
    GOSUB PrintMenu 'this sub prints the options to the screen
    K$ = UCASE$(INPUT$(1)) 'this tells the program what to do
    INPUT "Amount of transaction: ", amount
    CLS
    SELECT CASE K$

        CASE "C": balance = balance - amount
        CASE "D": balance = balance + amount

    END SELECT

    PRINT "Balance ="; balance

LOOP UNTIL K$ = "Q"
END


PrintMenu:
PRINT "Select a transaction type:"
PRINT "D = Deposit"
PRINT "C = Check"
PRINT "S = Service charge"
RETURN
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
moto1978
Newbie
Posts: 6
Joined: Thu Mar 08, 2012 6:27 pm

Post by moto1978 »

I tried this and it didn't produce a running balance.

I got help from another friend and came up with this.


CLS
GOSUB SetUpConstants
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB CalculateAnswer
GOSUB PrintDetail
END

REM SET UP CONSTANTS
SetUpConstants:
LET H$ = " Bank Balance"
LET H1$ = " Beginning Balance"
LET H2$ = " Transaction"
LET D1$ = "\ \ ### ## ###"
LET TOTAL$ = " Current Balance #### ### ###"
RETURN


PrintHeadings:
PRINT
PRINT H$
PRINT
PRINT H1$
PRINT
PRINT H2$
PRINT
RETURN


ProcessDetail:
GOSUB ReadData
DO WHILE UCASE$(Nam$) <> "END"
GOSUB CalculateAnswer
GOSUB PrintDetail
GOSUB ReadData
LOOP
RETURN

CalculateAnswer:



RETURN



ReadData:
READ Trans, Amount
DATA Check, 15.00
DATA Deposit, 50.50
DATA Check, 45.57
DATA Check, 5.00
DATA Deposit, 60.00
DATA Service Charge, 6.00
DATA END, 0, 0
RETURN


PrintDetail:
PRINT USING
RETURN

I'm sure it can be done much easier and shorter but I'm still lost. So this worked and I turned it in.

Thanks
Post Reply