C# Console App Carpet a Room

C# Console App Carpet a Room

26/04/2020 0 By Admin

This C# console app asks the user to input a range of data:

  • Room length;
  • Room width;
  • Senior’s discount or not choice;
  • Age.

Code Show

Code Awareness

  • Data Types:
    • int, float
  • Constant (variable)
  • If Else conditionals / flow control
  • int.Parse
  • Arithmetic operators
  • Operator precedence percentage calculation
  • Equality operator ==
  • Comparison operator >=
  • Console.WriteLine method
  • Console.ReadLine method
  • Environment.Exit(0) method
  • Formatting with \n
  • Formatting with foregroundColor

Notes

Line 14. int.Parse used to convert string input to int.

Line 16. int.Parse used to convert string input to int.

Line 18. float used to hand large numbers (see data types post).

Lines 24-34.

Conditional checks user input/choice and prints response to screen.

Terminates application if user inputs ‘no’.

Lines 36. float variable initialised with % calculation.

Lines 40-50.

Conditional checks users age input and prints response to screen.

Terminates application if age is not more than or equal to 55.