Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace numbersNs {
- public class numbers{
- private double _num1;
- public double num1{
- get {
- return _num1;
- }
- set {
- _num1 = value;
- }
- }
- private double _num2;
- public double num2{
- get {
- return _num2;
- }
- set {
- _num2 = value;
- }
- }
- private double _num3;
- public double num3{
- get {
- return _num3;
- }
- set {
- _num3 = value;
- }
- }
- private double _num4;
- public double num4{
- get {
- return _num4;
- }
- set {
- _num4 = value;
- }
- }
- private double _num5;
- public double num5{
- get {
- return _num5;
- }
- set {
- _num5 = value;
- }
- }
- public double numPositive{
- get {
- double _numPositive = 0;
- if( _num1 >= 0) _numPositive++;
- if( _num2 >= 0) _numPositive++;
- if( _num3 >= 0) _numPositive++;
- if( _num4 >= 0) _numPositive++;
- if( _num5 >= 0) _numPositive++;
- return _numPositive;
- }
- }
- public double numNegative{
- get {
- double _numNegative = 0;
- if( _num1 < 0) _numNegative++;
- if( _num2 < 0) _numNegative++;
- if( _num3 < 0) _numNegative++;
- if( _num4 < 0) _numNegative++;
- if( _num5 < 0) _numNegative++;
- return _numNegative;
- }
- }
- public double numSum{
- get {
- return _num1 + _num2 + _num3 + _num4 + _num5;
- }
- }
- public double numProduct{
- get {
- return _num1 * _num2 * _num3 * _num4 * _num5;
- }
- }
- }
- public class Program: numbers{
- public static void Main(){
- numbers nums = new numbers();
- double OutVal;
- bool looping = false;
- cls();
- print("Insert 5 numbers: \n");
- double.TryParse(input("First number: "), out OutVal);
- nums.num1 = OutVal;
- double.TryParse(input("Second number: "), out OutVal);
- nums.num2 = OutVal;
- double.TryParse(input("Third number: "), out OutVal);
- nums.num3 = OutVal;
- double.TryParse(input("Fourth number: "), out OutVal);
- nums.num4 = OutVal;
- double.TryParse(input("Fifth number: "), out OutVal);
- nums.num5 = OutVal;
- looping = true;
- cls();
- while (looping){
- print(String.Format("Numbers you have: \n{0} {1} {2} {3} {4}\n",nums.num1, nums.num2, nums.num3, nums.num4, nums.num5));
- print("\nWhat should I do now?");
- print("1 - Get the number of positive numbers");
- print("2 - Get the number of negative numbers");
- print("3 - Get sum of all the numbers");
- print("4 - Get product of all the numbers");
- print("5 - Exit\n");
- while (true){
- ConsoleKeyInfo Out = inputKey("Choose: ");
- if (Out.KeyChar.ToString() =="1")
- print(String.Format("\nAnswer: {0}",nums.numPositive));
- else if (Out.KeyChar.ToString() =="2")
- print(String.Format("\nAnswer: {0}",nums.numNegative));
- else if (Out.KeyChar.ToString() =="3")
- print(String.Format("\nAnswer: {0}",nums.numSum));
- else if (Out.KeyChar.ToString() =="4")
- print(String.Format("\nAnswer: {0}",nums.numProduct));
- else if (Out.KeyChar.ToString() =="5")
- looping = false;
- else {
- print("Error!");
- continue;
- }
- if (Out.KeyChar.ToString() !="5")
- inputKey("\nPress any key to continue...");
- cls();
- break;
- }
- }
- }
- static void setNumVal(object obj){
- double Out;
- while (true){
- double.TryParse(input(), out Out);
- if (double.IsNaN(Out)){
- print("Error!");
- continue;
- } else {
- obj = Out;
- break;
- }
- }
- }
- //simplified function for printing
- static void print(String str, bool newline = true)
- {
- if (newline)
- Console.WriteLine(str);
- else
- Console.Write(str);
- }
- //simplified function for getting the user input
- static String input(String str = "")
- {
- if (str != "") print(str,false);
- return Console.ReadLine();
- }
- //simplified function for getting the user input key
- static ConsoleKeyInfo inputKey(String str = "")
- {
- if (str != "") print(str,false);
- return Console.ReadKey();
- }
- //simplified function for clering the screen
- static void cls()
- {
- Console.Clear();
- }
- }
- }
Add Comment
Please, Sign In to add comment