Read double and int from console : Console Input Output « Development Class « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Development Class » Console Input OutputScreenshots 
Read double and int from console
 

using System;
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        (new Program()).run();
    }

    public void run() {
        double dailyRate = readDouble("Enter your daily rate: ");
        int noOfDays = readInt("Enter the number of days: ");
        writeFee(calculateFee(dailyRate, noOfDays));
    }

    private void writeFee(double p) {
        Console.WriteLine("The consultant's fee is: {0}", p * 1.1);
    }

    private double calculateFee(double dailyRate, int noOfDays) {
        return dailyRate * noOfDays;
    }

    private int readInt(string p) {
        Console.Write(p);
        string line = Console.ReadLine();
        return int.Parse(line);
    }

    private double readDouble(string p) {
        Console.Write(p);
        string line = Console.ReadLine();
        return double.Parse(line);
    }
}

 
Related examples in the same category
1.Read a character from the keyboardRead a character from the keyboard
2.Input from the console using ReadLine()Input from the console using ReadLine()
3.Read a string from the keyboard, using Console.In directlyRead a string from the keyboard, using Console.In directly
4.Write to Console.Out and Console.ErrorWrite to Console.Out and Console.Error
5.Output with parameters
6.Illustrates how to read a character entered using the keyboardIllustrates how to read a character entered using the keyboard
7.Illustrates how to read a string entered using the keyboardIllustrates how to read a string entered using the keyboard
8.Read a line from consoleRead a line from console
9.Demonstrates redirecting the Console output to a fileDemonstrates redirecting the Console output to a file
10.Console command-line argumentsConsole command-line arguments
11.Use format commandsUse format commands
12.Redirect Console.OutRedirect Console.Out
13.This program averages a list of numbers entered by the userThis program averages a list of numbers entered by the user
14.Demonstrate various format specifiersDemonstrate various format specifiers
15.While loop and keyboard readingWhile loop and keyboard reading
16.Demonstrates some of the formatting flags for writing text to the consoleDemonstrates some of the formatting flags for writing text                to the console
17.Uses the #, 0 and comma characters to format outputUses the #, 0 and comma characters to format output
18.A simple command line program that reads from the console using Console.Read() and Console.ReadLine()A simple command line program that reads from     the console using Console.Read() and Console.ReadLine()
19.C# Basic Data TypesC# Basic Data Types
20.C# Hello UniverseC# Hello Universe
21.Terminate a control input
22.Use do while to read console input
23.Use while(true) to read console input
24.Convert input from control to upper case
25.constructs sentences by concatenating user input until the user enters one of the termination characters
26.input a series of numbers separated by commas, parse them into integers and output the sum
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.