Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft CSharp Programming For The Absolute Beginner (2002) [eng]-1.pdf
Скачиваний:
46
Добавлен:
16.08.2013
Размер:
15.71 Mб
Скачать

Summary

This chapter leads you through the murky swamp of computer mathematics (well, around the fringes anyway). You have learned a few important ways that computers store numeric values. You’ve learned the basic numeric variable types and how to convert between them. You know how to create a random double and how to change that double into any range of integers you want. You also know how to cause a branch in the computer’s behavior, based on a certain condition. You should be proud because you’ve learned a lot already. In the next chapter, you will learn how to make your programs repeat, which will contribute tremendously to the kinds of programs you can write.

Challenges

Write a program that simulates a coin toss. Generate a random number between 0 and 1. If that value is less than .5, make it heads. Otherwise, output tails.

Many role−playing games require dice with a different number of faces than the traditional six−sided cube. Write a program that asks the user how many sides the die should have, and give a random result in the appropriate range.

Write a program that simulates a “loaded” die that comes up with the value 1 for half the time and some other random value the other half of the time.

Make the Math Game more advanced by incorporating other math operators. Look up the math object in the .NET reference for interesting operators such as Math.Abs (absolute value) and Math.Pow (used for exponentiation).

54

Соседние файлы в предмете Программирование на C++