Zebra0.com

csharp functions

An organization wants to take a trip. We need enough busses to fit everyone. (We can't tell a few people that they can't go.)

If we divide 30/25 we will get just one. However, 30.0/25 gives us 1.2

Notice that the Ceiling function will give us the correct number of busses the ceiling of 1.2 is 2.

The text that appears will be "You will need 2 busses"

int numPeople = 30; //input from scroll bar
int seats = 25; //input from scroll bar
double num = 1.0*numPeople / seats; //multiply by 1.0 to cast to double
int numBusses =(int) Math.Ceiling(num); //cast to integer
this.Text = "You will need " + numBusses + " busses"; //use + for concatenation

End of lesson, Next lesson: