Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-starter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
go-exercises
go-starter
Commits
95391ba7
Commit
95391ba7
authored
2 years ago
by
Martin Schmollinger
Browse files
Options
Downloads
Patches
Plain Diff
Solution to exercise of unit 04-02
parent
cf413363
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
exercise_0402/go.mod
+3
-0
3 additions, 0 deletions
exercise_0402/go.mod
exercise_0402/main.go
+37
-0
37 additions, 0 deletions
exercise_0402/main.go
with
40 additions
and
0 deletions
exercise_0402/go.mod
0 → 100644
+
3
−
0
View file @
95391ba7
module gitlab.reutlingen-university.de/go-exercises/go-starter/exercise_0402
go 1.20
This diff is collapsed.
Click to expand it.
exercise_0402/main.go
0 → 100644
+
37
−
0
View file @
95391ba7
package
main
import
(
"errors"
"fmt"
)
type
BankAccount
struct
{
balance
float32
limit
float32
}
func
(
ba
*
BankAccount
)
Withdraw
(
amount
float32
)
error
{
if
amount
>
ba
.
balance
+
ba
.
limit
{
return
errors
.
New
(
"amount currently not available"
)
}
else
{
ba
.
balance
-=
amount
return
nil
}
}
func
main
()
{
ba
:=
BankAccount
{
balance
:
1000.0
,
limit
:
3000.0
,
}
fmt
.
Printf
(
"%v
\n
"
,
ba
)
if
err
:=
ba
.
Withdraw
(
5000
);
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
fmt
.
Printf
(
"%v
\n
"
,
ba
)
if
err
:=
ba
.
Withdraw
(
1000
);
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
}
fmt
.
Printf
(
"%v
\n
"
,
ba
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment