September 2002
Intermediate to advanced
496 pages
10h
English
Our “Hello, World” program illustrated the basic structure of a C# program and introduced classes and components, but we need a slightly more elaborate example to show the use of other basic programming constructs, such as variables, expressions, and control structures. Our next example is a simple calculator for a savings account. The user is prompted for annual contribution, interest rate, and number of years. We calculate the accumulation of deposits two ways:
In a loop, year by year, accumulating a total as we go
Using a formula
The example program is in the folder Savings.
// Savings.cs using System; class Savings { public static void Main(string[] args) { InputWrapper iw = new InputWrapper(); decimal amount; ...Read now
Unlock full access