
Ritchie asked us to try creating a double variable and then output it to the screen.īy default, every real number in C# program is treated as a double. double temperature = 17.5 Ĭonsole.WriteLine(temperature) // Outputs: 17.5Ĭonsole.WriteLine("Temp is " + temperature) // Outputs: Temp is 17.5Ĭonsole.WriteLine($"Temp is ") // Outputs: Temp is 17.5Įveryone in the room was nodding. To output a double to the screen or concatenate it with a string, you use exactly the same mechanisms as you used with an int. String result6 = someString * someString // NOT ok - can't multiply strings String result5 = someString / someDouble // NOT ok - can't divide string on String result4 = someString * someInt // NOT ok - can't multiply int and String result3 = someString + someInt // Ok - append int to string String result2 = someString + someDouble // Ok - append double to string

Here are some examples:ĭouble result1 = someDouble + someInt // Ok - adding double and int

You can only add strings (using "+") to numeric types. At the same time, you cannot multiply strings with any other type, or divide or subtract. We can add integers and real numbers, subtract them, divide them, and multiply them without any hiccups. This isn't any different than how you do things outside of coding. The result is automatically converted to a double type." double someDouble = 7.5 Ĭonsole.WriteLine(subtract) // Outputs 5.5Ĭonsole.WriteLine(multiply) // Outputs 15Ĭonsole.WriteLine(divide) // Outputs 3.75 "Even better," he said, "you can add, subtract, divide, and multiply double and int variables together. Ritchie continued making the case for the new types. He continued, "I know it seems complicated, but you can add, subtract, divide, and multiply double variables same as you do with integers." double myMoney = 10.25 Ĭonsole.WriteLine(fourTimesMyMoney) // Outputs 41Ĭonsole.WriteLine(decreasedMoney) // Outputs 9ĭouble dividedMoney = decreasedMymoney / 2 Ĭonsole.WriteLine(dividedMoney) // Outputs 4.5ĭouble addToMyMoney = dividedMoney + 100.34 Ĭonsole.WriteLine(addToMyMoney) // Outputs 104.84 In a similar manner, you can use a double variable to store a real number inside:" You could have 1.50 dollars, or 1.63 dollars, not just 1 or 2. Before our time though, people had a currency - the dollar - to calculate their money. You can have 2, 5, or 10 viruses, but not 2.5, right? That's why you think in terms of the int type. Every number of viruses is an integer number. "In our world, the primary currency is viruses. Ritchie had clearly anticipated this question. "I use int in all my programs and everything seems to work fine!" "Why would we need such complexity?" someone asked, mirroring my own thoughts. For example," at this, Ritchie uncapped a marker and began writing on the whiteboard behind him, "numbers like 2.5, 17.9456, and 0.7 are real numbers." Both of these types represent a real number, sometimes referred to as a floating-point number (this is where the name 'float' goes from). Let's start simple and go over some of the built-in types, the first of which are the float and double types. There are so-called built-in types, which are more complex types than string and the other types we already know. "More? Really?" Someone from the crowd called. It turns out there are many more types than just bool, int, and string. I've just returned from the machine city, and an ally of ours shared some intel they've been working on obtaining for a while. "Hello, everyone! Thank you all for coming on such short notice. People were still trickling in little by little, and everyone was waiting for him to begin. Ritchie was standing at the front of the kitchen, and most of the tables were full. He called a meeting in the big kitchen at." Jessica looked at her watch, "Now! Let's go!" I turned on my heels and tried to keep up. "Ritchie returned from an expedition and said he had something to show off. I suddenly noticed that everyone other than me was headed in the other direction. "Thanks, you look pretty chipper yourself!" I returned. Jessica was heading toward me in the corridor. By the looks of it, no one had particularly noticed my absence, which meant that I should be able to continue helping Noname to restore his modules without drawing suspicion.

In this dark and grim world, I finally had at least one hope to hold onto - the hope that there was at least a chance that I could make it back to my own time.įor a few days after getting into the basement and back out again, I engaged in some people watching whenever I was moving around the base. My mood was much better after visiting the basement.
