Skip to content

Commit 1ceb819

Browse files
committed
Add MadLibs solution code
1 parent a3ad125 commit 1ceb819

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

2-data-types-variables/MadLibs.kt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
fun main () {
2+
3+
val costOfGas = 2.28
4+
val mileage = 25
5+
6+
// Declare the variable distance below
7+
val distance: Int
8+
9+
println("What's your name?")
10+
var name = readLine()
11+
12+
println("What's your friend's name?")
13+
var friendsName = readLine()
14+
15+
println("What adjective would you like to use?")
16+
var adjective = readLine()
17+
18+
println("What city will you be driving to?")
19+
var city = readLine()
20+
21+
println("What's your favorite band's name?")
22+
var bandName = readLine()
23+
24+
println("What will you and $friendsName work as?")
25+
var work = readLine()
26+
27+
println("Enter an amount of miles between 400 and 600")
28+
29+
// Initialize the variable named distance below
30+
distance = Integer.valueOf(readLine())
31+
32+
// Calculate the total cost for gas and store it in a variable called totalForGas below
33+
var totalForGas = (costOfGas / mileage) * distance
34+
totalForGas = Math.round(totalForGas * 100) / 100.00
35+
36+
// Create the variable named totalMoneySaved below
37+
var totalMoneySaved = totalForGas + 200
38+
39+
print("""
40+
A long time ago, $name and their friend $friendsName planned a(n) $adjective road trip to see their favorite band: $bandName.
41+
The venue was $distance miles away which meant they needed to save $$totalForGas dollars to get there.
42+
Both of them worked as $work for the whole summer and managed to save up a total of $$totalMoneySaved dollars!
43+
To celebrate, they ended up driving to $city for the whole weekend; seeing their band and buying $bandName t-shirts to remember their trip.
44+
""".trimIndent())
45+
}

0 commit comments

Comments
 (0)