Story Continues
(You would not understand the story if you haven't read GO 101: Days 1 and 2. Use the keywords I provided below to help you know the story.)
Keyword
- Crab Cult = Rust users (Taking over the world)
- Gophers = GO user (Volunteered To Stop Crab Cult)
- Z+ Cult = Zig Users (Volunteered To Stop Crab Cult)
- Elderly men = C and C++ (Murdered by Crab Cult)
- Police Officers = Python Users and Web Developers (Afraid Crab Cult)
- Typers++ = TypeScript Users
- Coffee Lovers = JavaScript Users (Java means "a beverage consisting of an infusion of ground coffee beans")
- Spiders = Web Developers -Soft Cult = Software Developers
Context
Crab Cult is starting to become dangerous day by day. There is no one to stop them. Police officers are afraid to stand against the power of Underworld Gangsters (low-level languages), and those who could have defeated the Crab Cult have already been murdered by the Crab Cult.
At the end, officers had no choice but to call for help, but everyone was afraid of the Crab Cult. In the whole world, no one was ready to stand against them except
Gophers
Z++ Cult
Typers recently got protection from Gophers because Gophers knew the next target of the carb cult were typers. This led to chaos in the cult's headquarters
What Next?
Seeing all these police officers started to become less afraid of the crab cult.
They started to rise and prove they are better than the crab cult. Many also protested that elderly men are still the GOAT.
CodeTube was filled with Gophers that day.
But Crab Cult weren't losing this early my boy.
.....TO BE CONTINUED
What is GO 101
Here, I randomly make anything in GO. Without any help from LLM or any tutorial.
The only thing I can use is the GO Documentation for syntax only and nothing, and I have to do this for the next 30 Days to track the improvement.
Day 3
I planned to take my Day 1 CLI calculator to the next level.
The plan was that I would take 2 inputs from the user and using that two inputs, I would calculate 10 random maths operations or formulas.
My previous calculator already had 5 mathematical operations:
- Add
- Subtract
- Multiply
- Divide
- Remainder
And the next 5 I was planning were
- Perimeter (Applicable for Square & Rectangle only)
- Area (Applicable for Square & Rectangle only)
- Power (x**y)
- Hypotenuse (Pythagoras' theorem considering the user hasn't inputted the hypotenuse)
- Aligattor (I don't know what its called but it basically <,>,==)
But how would I improve? I have already done maths on Day 1.
That's where functions come into play. This time, I would use functions and call them.
(SECRET: Using function would help me extend this program more, which means you would have to study more maths in the upcoming GO 101 post)
Implementation
Pseduo Code
- Print some basic statements
- Ask for user input and store it in variable a and b which are float32 type
- Create functions that return the value
- Print the returned value
Real Code
package main
import (
"fmt"
"math"
)
func main() {
var a float32
var b float32
fmt.Println("This is a maths project made by Dat_One_Dev(Kartik Patel) for Go 101: Day 3")
fmt.Println("Just enter A and B and see magic")
fmt.Println("Formulas are taken with A first and B second")
fmt.Print("Enter A: ")
fmt.Scanln(&a)
fmt.Print("Enter B: ")
fmt.Scanln(&b)
fmt.Print("Addition: ")
fmt.Println(addition(a, b))
fmt.Print("subtraction: ")
fmt.Println(subtraction(a, b))
fmt.Print("division: ")
fmt.Println(division(a, b))
fmt.Print("multiplication: ")
fmt.Println(multiplication(a, b))
fmt.Print("area: ")
fmt.Println(area(a, b))
fmt.Print("hypotenus: ")
fmt.Println(hypotenus(float64(a), float64(b)))
fmt.Print("Perimeter: ")
fmt.Println(perimeter(a, b))
fmt.Print("Remainder: ")
fmt.Println(modulus(a, b))
fmt.Print("Greater/Lesser/Equal: ")
fmt.Println(alligator(a, b))
fmt.Print("Power: ")
fmt.Println(power(a, b))
}
func addition(x float32, y float32) float32 {
return x + y
}
func subtraction(x float32, y float32) float32 {
return x - y
}
func division(x float32, y float32) float32 {
return x / y
}
func multiplication(x float32, y float32) float32 {
return x * y
}
func hypotenus(x float64, y float64) float64 {
//taking x is a^2 and y is b^2 in a^2+b^2 = c^2
return math.Sqrt(x*x + y*y)
}
func area(x float32, y float32) any {
return x * y
}
func perimeter(x float32, y float32) float32 {
return x*2 + y*2
}
func modulus(x float32, y float32) int {
return int(x) % int(y)
}
func alligator(x float32, y float32) string {
if x > y {
return "X is more than y"
} else if x < y {
return "x is less than y"
} else if x == y {
return "x and y are same"
} else {
return "IDK, Its your fault you broke the program"
}
}
func power(x float32, y float32) float64 {
return math.Pow(float64(x), float64(y))
}
It's Your Turn
Previously (Day 1), I had used LLM to find mistakes in my program, which I have clearly stated in my blog by providing what I wrote and what I should have written according to LLM. Many people didn't like it, so this time I leave this up to you. Go comment below on what you think is the issue with this program. How can it be improved?
What I think
As I say in every one of my previous GO 101 posts, I am struggling with finding out what data type the user has inputted a value in. (And more pain is that I can't search it on Google cause that's the rule).
Only you could help me with this by commenting down as I am allowed to read your comment.
Another new thing I found myself struggling with this time was whenever I use any function from the math library, there are some issues with the data type.
Take a look here
package main
import "fmt"
import "math"
func main(){
fmt.Println(hypotenus(float64(a), float64(b)))
}
func power(x float32, y float32) float64 {
return math.Pow(float64(x), float64(y))
}
func hypotenus(x float64, y float64) float64 {
//taking x is a^2 and y is b^2 in a^2+b^2 = c^2
return math.Sqrt(x*x + y*y)
}
This is a snippet from my code. I don't know what the issue was, to be honest, and before someone asks, how I fixed it when I didn't even know the issue.
Then I would give a special thanks to the GO vs code extension, the error message he gave was enough for me to get a hint on what I should do.
Here is the extension that I am using.
Outro
Recommended Post:
Mini Micro
GO
Conceptual
Developer Essential
Learn By Code and Code Review
Top comments (0)