🔒 Closed (C#)Pa check po ng code ko sa c# thanks..

Status
Not open for further replies.

Nero Swallowtail

Honorary Poster
Di ko sure kung tama tong nagawa ko e, pa check nga po ako kung tama , feel ko tama ko yung number 2 sa number 1 lang ako nalilito, salamat po sa sasagot.
Eto yung instruction:
You do not have permission to view the full content of this post. Log in or register now.
Eto yung code:

You do not have permission to view the full content of this post. Log in or register now.
Hide react ko lang para pam pa elite, charot para di magulo hehe
 
Ganito ba need mo sa number 1? yung magagamit ang 3 types (int, double, long) pero ang return is int?

NOTE: C# 5.0 gamit ko

C#:
  using System;

    Calculator calculator = new();

    Console.WriteLine("Number 1.");

    Console.Write("Enter the first number: ");
    int num1 = Convert.ToInt32(Console.ReadLine());

    Console.Write("Enter the second number: ");
    int num2 = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine($"Total: {calculator.Compute(num1, num2)}\n");

    Console.Write("Enter the first number: ");
    double num3 = Convert.ToDouble(Console.ReadLine());

    Console.Write("Enter the second number: ");
    double num4 = Convert.ToDouble(Console.ReadLine());

    Console.WriteLine($"Total: {calculator.Compute(num3, num4)}\n");

    Console.Write("Enter the first number: ");
    long num5 = Convert.ToInt64(Console.ReadLine());

    Console.Write("Enter the second number: ");
    long num6 = Convert.ToInt64(Console.ReadLine());

    Console.WriteLine($"Total: {calculator.Compute(num5, num6)}\n");

    public class Calculator{
        public int Compute(int n1, int n2) => n2 + n2;
        public int Compute(double n1, double n2) => (int)(n1 + n2);
        public int Compute(long n1, long n2) => (int)(n1 + n2);
    }

Yung sa code mo sa methods like this:
Code:
private int getNum(double firstNum, double secondNum)
{
    double total = firstNum + secondNum;
    int newTotal = (int)total;
    return newTotal;
}

Di mo na need ideclare as double yung firstnum + secondNum.
since yung params nila ay double na. Pwede mo nalang direct convert and retrun to int yung total
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 2
    Replies
  • 449
    Views
  • 2
    Participants
Last reply from:
zackmark29

Trending Topics

Online now

Members online
1,195
Guests online
1,788
Total visitors
2,983

Forum statistics

Threads
2,294,664
Posts
29,092,532
Members
1,207,439
Latest member
TawAs
Back
Top