Is FreeBASIC good for beginners to progrmaming?
Re: Is FreeBASIC good for beginners to progrmaming?
Looks good, @joeyxl. Maybe as a next step add logic that prevents you from overdrawing your account.
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Is FreeBASIC good for beginners to progrmaming?
Looks ok to me. Well done. Now we can tell you how to improve it :)
Last edited by BasicCoder2 on Jun 14, 2021 3:14, edited 3 times in total.
Re: Is FreeBASIC good for beginners to progrmaming?
Whenever a single variable is tested for different values only, Select Case i
statement is the better choice, than "endless if's" (or elseif's).
statement is the better choice, than "endless if's" (or elseif's).
-
- Posts: 4310
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Is FreeBASIC good for beginners to progrmaming?
@joeyxl
You are hooked.
You are hooked.
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Is FreeBASIC good for beginners to progrmaming?
. deleted
Last edited by BasicCoder2 on Jun 14, 2021 6:36, edited 1 time in total.
-
- Posts: 4310
- Joined: Jan 02, 2017 0:34
- Location: UK
- Contact:
Re: Is FreeBASIC good for beginners to progrmaming?
@BasicCoder2
You are rushing him and imposing your ideas; it may not be what he has in mind.
You are rushing him and imposing your ideas; it may not be what he has in mind.
So let him develop. We can suggest better ways of doing something, but the ideas should come from him.joeyxl wrote:i actually plan on adding more to it as i learn more.
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Is FreeBASIC good for beginners to progrmaming?
Ok. I have deleted the suggested methodology. I thought I was suggesting better ways of doing it. It was the kind of feedback I would have appreciated when I was a programming neophyte. He was always free to ignore it but at least it was there should he have chosen to learn from it.deltarho[1859] wrote:@BasicCoder2
You are rushing him and imposing your ideas; it may not be what he has in mind.So let him develop. We can suggest better ways of doing something, but the ideas should come from him.joeyxl wrote:i actually plan on adding more to it as i learn more.
.
Re: Is FreeBASIC good for beginners to progrmaming?
What did you say? I'm sure it's fine.BasicCoder2 wrote:Ok. I have deleted the suggested methodology. I thought I was suggesting better ways of doing it. It was the kind of feedback I would have appreciated when I was a programming neophyte. He was always free to ignore it but at least it was there should he have chosen to learn from it.deltarho[1859] wrote:@BasicCoder2
You are rushing him and imposing your ideas; it may not be what he has in mind.So let him develop. We can suggest better ways of doing something, but the ideas should come from him.joeyxl wrote:i actually plan on adding more to it as i learn more.
.
Re: Is FreeBASIC good for beginners to progrmaming?
I think BasicCoder2 can restore its previous post which offered structure and sample code.
Re: Is FreeBASIC good for beginners to progrmaming?
I was personally ok with his first comment that he edited. He called me out on my grammar and that's cool, I know i have some bad grammar lol.fxm wrote:I think BasicCoder2 can restore its previous post which offered structure and sample code.
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Is FreeBASIC good for beginners to progrmaming?
Not your grammar just the spelling of withdrawal. I use a spell checker :)
Making use of functions you can break your code into modules which makes it easier to read and modify.
You can define a TYPE to store account data. I have only defined one variable, balance, but more can be added.
Making use of functions you can break your code into modules which makes it easier to read and modify.
You can define a TYPE to store account data. I have only defined one variable, balance, but more can be added.
Code: Select all
'define a type
type ACCOUNT
as single balance
end type
dim as ACCOUNT myAccount 'create an ACCOUNT type called myAccount
'initialize myAccount
myAccount.balance = 0
function getChoice() as integer
dim as integer selection = 0
Print "(1) balance"
Print "(2) deposit"
Print "(3) withdrawal"
Print "(4) exit"
Print
while selection = 0
input "Please make a choice.";selection
if selection > 4 or selection < 1 then
locate 11,2
print " That is an invalid selection. Try again"
end if
wend
return selection
end function
sub printBalance(acc as ACCOUNT)
Print
Print "Your Balance is:"; acc.balance
Print
end sub
sub makeDeposit(acc as ACCOUNT)
dim as string reply
dim as single deposit
print
Input "Please type in how much you would like to deposit: ", deposit
Print "OK, you deposited"; deposit
acc.balance += deposit
Input "Would you like to see your balance, yes/no ? ", reply
If reply = "yes" Then
Print
Print "Your Balance is:";acc.balance
Print
End If
end sub
sub makeWithdrawal(acc as ACCOUNT)
dim as single withdrawal
dim as string reply
print
Input "Please type in how much you would like to withdraw: ", withdrawal
if acc.balance - withdrawal < 0 then
print
print "Sorry. You have insufficient funds for that amount."
else
Print "OK, you withdrew"; withdrawal
acc.balance -= withdrawal
Input "Would you like to see your balance yes/no ?", reply
If reply = "yes" Then
Print
Print "Your balance is:" ;acc.balance
Print
End If
end if
Print
end sub
Print "Hello, and welcome to the atm software"
print
Do
Select Case getChoice()
Case 1
printBalance(myAccount)
Case 2
makeDeposit(myAccount)
Case 3
makeWithdrawal(myAccount)
Case 4
Exit Do
End Select
Loop
Print
Print "Thank you for using our service. goodbye"
Sleep
Re: Is FreeBASIC good for beginners to progrmaming?
wow, that is so much better than the one i made. using sub routines for each action.BasicCoder2 wrote:Not your grammar just the spelling of withdrawal. I use a spell checker :)
Making use of functions you can break your code into modules which makes it easier to read and modify.
You can define a TYPE to store account data. I have only defined one variable, balance, but more can be added.
Code: Select all
'define a type type ACCOUNT as single balance end type dim as ACCOUNT myAccount 'create an ACCOUNT type called myAccount 'initialize myAccount myAccount.balance = 0 function getChoice() as integer dim as integer selection = 0 Print "(1) balance" Print "(2) deposit" Print "(3) withdrawal" Print "(4) exit" Print while selection = 0 input "Please make a choice.";selection if selection > 4 or selection < 1 then locate 11,2 print " That is an invalid selection. Try again" end if wend return selection end function sub printBalance(acc as ACCOUNT) Print Print "Your Balance is:"; acc.balance Print end sub sub makeDeposit(acc as ACCOUNT) dim as string reply dim as single deposit print Input "Please type in how much you would like to deposit: ", deposit Print "OK, you deposited"; deposit acc.balance += deposit Input "Would you like to see your balance, yes/no ? ", reply If reply = "yes" Then Print Print "Your Balance is:";acc.balance Print End If end sub sub makeWithdrawal(acc as ACCOUNT) dim as single withdrawal dim as string reply print Input "Please type in how much you would like to withdraw: ", withdrawal if acc.balance - withdrawal < 0 then print print "Sorry. You have insufficient funds for that amount." else Print "OK, you withdrew"; withdrawal acc.balance -= withdrawal Input "Would you like to see your balance yes/no ?", reply If reply = "yes" Then Print Print "Your balance is:" ;acc.balance Print End If end if Print end sub Print "Hello, and welcome to the atm software" print Do Select Case getChoice() Case 1 printBalance(myAccount) Case 2 makeDeposit(myAccount) Case 3 makeWithdrawal(myAccount) Case 4 Exit Do End Select Loop Print Print "Thank you for using our service. goodbye" Sleep
Re: Is FreeBASIC good for beginners to progrmaming?
It can even be made more complete.
Attaching Type specific procedures to the type they belong to:
BTW: copying the whole previous post is a waste of forum resources.
(just copy the part that you want to reference your answer to)
Attaching Type specific procedures to the type they belong to:
Code: Select all
' ----- define a type -----
type ACCOUNT
as Double balance
Declare Sub addACC() ' deposit
Declare Sub subAcc() ' withdrawal
Declare Sub Show() ' show balance
End Type
sub ACCOUNT.Show()
Print
Print "Your current Balance is: "; This.balance
Print
end Sub
Sub ACCOUNT.addAcc()
dim as Double deposit
print
Input "Please type in how much you would like to deposit: ", deposit
Print "OK, you deposited "; deposit
This.balance += deposit
Print
Print "Your NEW balance is now: "; This.balance
End sub
Sub ACCOUNT.subAcc()
dim as Double withdrawal
print
Input "Please type in how much you would like to withdraw: ", withdrawal
if This.balance - withdrawal < 0 then
print
print "Sorry. You have insufficient funds for that amount."
else
Print "OK, you withdrew"; withdrawal
This.balance -= withdrawal
Print
Print "Your NEW balance is now: "; This.balance
end if
Print
end Sub
' ----- type end -----
' program specific menu ...
function Menu() as UByte
dim as integer selection = 0
Print
Print "(1) balance"
Print "(2) deposit"
Print "(3) withdrawal"
Print "(4) exit"
Print
while selection = 0
input "Please make a choice.",selection
if selection > 4 OrElse selection < 1 then
locate 11, 2
print "That is an invalid selection. Try again"
end If
Sleep 10, 1
wend
return selection
end Function
' MAIN
dim as ACCOUNT myAccount 'create an ACCOUNT type called myAccount
'initialize myAccount
myAccount.balance = 0
Print "Hello, and welcome to the atm software"
print
Do
Select Case As Const Menu
Case 1 : myAccount.Show
Case 2 : myAccount.addACC
Case 3 : myAccount.subAcc
Case 4 : Exit Do
End Select
Sleep(50, 1)
Loop
Print
Print "Thank you for using our service. goodbye"
Sleep
' ----- EOF -----
(just copy the part that you want to reference your answer to)
-
- Posts: 3906
- Joined: Jan 01, 2009 7:03
- Location: Australia
Re: Is FreeBASIC good for beginners to progrmaming?
@joeyxl
deltarho[1859] has a point when he warned against rushing someone ahead too fast. You will only lose heart and think it is all too hard. Best to move at your own speed with code you can fully understand and could write yourself. Move at your own pace, and take on new methods only when you are able to or want to.
deltarho[1859] has a point when he warned against rushing someone ahead too fast. You will only lose heart and think it is all too hard. Best to move at your own speed with code you can fully understand and could write yourself. Move at your own pace, and take on new methods only when you are able to or want to.
Last edited by BasicCoder2 on Jun 15, 2021 0:58, edited 4 times in total.
Re: Is FreeBASIC good for beginners to progrmaming?
Yes I see that logic. That's why im not copying his version at all. Im just going to do improvements at my own pace how I want it to turn out. It was just nice to see an alternative. I didn't loose heart :)BasicCoder2 wrote:@joeyxl
deltarho[1859] has a point when he warned against rushing someone ahead too fast. You will only lose heart and think it is all too hard. Best to move at your own speed with code you can fully understand and could write yourself. Move at your own pace, and take on new methods only when you are able to or want to.