Getting Numbers

Line: Input Line
Easy Input Learning Outcome One Walkthrough
Type: Walkthrough
You should have completed: Business Card This topic leads to:

Retirement Planner

Driving Test

Summary

The data input so far has all been in the form of strings. In order to get numbers for our program to work with, we need to convert the strings the user types in into a number data type.

Task

  1. Create a new console application
  2. Within "main" type in the following code
    Code Snippet title=
  3. Run the program and enter '12'
  4. Run the program and enter 'Bob'
  5. The program crashes with an exception, as 'Bob' cannot be parsed into a number. Ways of dealing with this will be explored later in the module.

Questions

  1. How could you modify the program so that it will work when the user enters '5.5'? Hint: Look up Int32 and Single in the Microsoft C# Reference.