September 4, 2018
int
named intVar
, one that declares a variable of type string
named stringVar
.3
to intVar
, and "4"
to stringVar
.intVar
and stringVar
.stringVar
to intVar
. Why is the compiler complaining?Copy the following statement, to “convert” the string value of stringVar
into an integer value, and assign it to intVar
:
Change the value of stringVar
to be "Train"
and assign it to intVar
using int.Parse
as previously shown. What happened?
int
, one of type float
, and one of type double
.We can use the following to read an int
from the user (assuming your int
variable is named intVar
):
Similarly, we can read float
using float.Parse(Console.ReadLine())
, and double using double.Parse(Console.ReadLine())
.
Write statements that ask the user to enter an int
, a float
and a double
, store those values in the appropriate variables, and then print them.
You accomplished a lot since you started this class. Let’s take a moment to look back at what you learned, and to make sure you understand all those notions and skills. If you have a doubt, feel free to look back at the corresponding lab.
Write
and WriteLine
,Maybe you decided what your major was going to be. Maybe you changed your mind. Maybe you’re not sure. Being confused and uncertain is sometimes part of the process of taking decisions and learning, and that’s all right. It is normal to hesitate. This page by a colleague in Computer Science may be a good read for students hesitating between IT, CS and MIS, or wanting to have more information about those majors.
Here is a problem that involves almost all the previously mentioned notions and skills. It is phrased in a more abstract way, closer to the kind of problem you will be facing if you were a software-developer. Think about what you need to do before starting to type your code, and when you start writing your code, make sure you compile it frequently.
Write a program that asks the user for their name, their number of guests, and the number of pizza slices they have. Your program should then display the name of the user, the number of people at the party, the number of pizzas slices, and how many slices will each guest have, assuming the slices will be shared equitably.
A couple of additional precisions: