logo
down
shadow

Basic OOP console calculator, result Error


Basic OOP console calculator, result Error

Content Index :

Basic OOP console calculator, result Error
Tag : chash , By : Hugo
Date : January 12 2021, 09:11 PM

it should still fix some issue I am new to programming and I am trying to code my very first OOP program in C# but it does not give the right results. , Three problems with your code:
static void Main(string[] args)
{
    CalcOperations calcOperations = new CalcOperations();
    Console.WriteLine("Welcome to basic OOP calculator! Enter a number. {0}1 - Addition{0}2 - Substraction{0}3 - Multiplication{0}4 - Division", Environment.NewLine);


    var userInput = int.Parse(Console.ReadKey().KeyChar.ToString());
    Console.WriteLine();

    GetUserInput(calcOperations);

var getOperation = new double[]{
                           calcOperations.Counting(),
                           calcOperations.Subtraction(),
                           calcOperations.Multiplication(),
                           calcOperations.Division()
    };
    Console.WriteLine(getOperation[userInput-1]);

    Console.ReadKey();
}
static void GetUserInput(CalcOperations calcOperations)
{
    Console.WriteLine("Enter the 1. number: ");
    calcOperations.firstNum = double.Parse(Console.ReadLine());
    Console.WriteLine("Enter the 2. number: ");
    calcOperations.secondNum = double.Parse(Console.ReadLine());
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

php basic calculator with function and switch but result is


Tag : php , By : AdrianB
Date : March 29 2020, 07:55 AM
With these it helps i am currently doing some simple calculator for a practice but it the output or result is not showing here is my code guys hope you can help me :/ , Here is complete code:
<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$calcu = $_POST['calcu'];

    function calculate($n1,$n2, $calcu) // set $calcu as parameter
    {
        switch($calcu)
        {
        case "Addition": // here you have to use colons not semi-colons
            $compute = $n1 + $n2; 
            break;
        case "Subtraction":
            $compute = $n1 - $n2; 
            break;
        case "Multiplication":
            $compute = $n1 * $n2; 
            break;
        case "Division":
            $compute = $n1 / $n2; 
            break;
        }
        return $compute; // returning variable
    }
echo "$calcu <br /> <br /> 1st Number: $num1 <br /> 2nd Number: $num2 <br /><br />";
echo "Answer is:" .calculate($num1,$num2, $calcu); // you need to pass $calcu as argument of that function
?>

Trying to develop a basic calculator in android studio. Error: "Unfortunately, Calculator has stopped"


Tag : development , By : antonio
Date : March 29 2020, 07:55 AM
I wish did fix the issue. java Code: , This is wrong:
 number1 = (EditText)findViewById(R.id.number1);
 a=Integer.parseInt(number1.getText().toString());

 number2 = (EditText)findViewById(R.id.number2);
 b=Integer.parseInt(number2.getText().toString());

How can I store the result of a calculator and return with alert or console.log?


Tag : javascript , By : Doc Immortal
Date : March 29 2020, 07:55 AM
hope this fix your issue You don't need the global answer variable there.
Change your return statements to simply return the result instead of trying to assign it to "answer". ie
switch(op){
case '+' : 
  return a+b 
  break;
case '-' : 
  return a-b 
  break;
case '*' : 
  return a*b 
  break;
case '/' : 
  return a/b 
  break;
}
console.log(mycal(a,b,op))
var answer = mycal(a,b,op)    
console.log(answer)

Basic calculator error in C++


Tag : cpp , By : kuba53280
Date : March 29 2020, 07:55 AM

Visual Basic BMI Calculator gives NaN result


Tag : vb.net , By : usingtechnology
Date : March 29 2020, 07:55 AM
I wish this helpful for you There are a few problems with your (meaning kushlord420) solution.
Visual Basic code in case insensitive so bmi is the same as BMI You never use the Form level variable bmi so delete. You tried to write a custom constructor but in vb.net it is Sub New You are converting the values in the weight and height text boxes to Double but your properties are type Single. Actually this should be Single.TryParse but that is for another day. Functions in vb.net must have a data type for the return value. This is provided in the first line of the function. Since you are using Format on the return value I made the value a String and converted the return value. Fixed the constructor parameters to avoid ambiguity.
    Sub Button_Calculate_Click(sender As Object, e As EventArgs) Handles Button_Calculate.Click
        Dim bmi As New BMI(CSng(TextBox_Weight.Text), CSng(TextBox_Height.Text))
        TextBox_BMI.Text = Format(bmi.GetBMI(), "0.00")
    End Sub

    Public Class BMI
        Public Function GetBMI() As String
            Return (Weight / (Height ^ 2)).ToString
        End Function

        Public Property Weight As Single
        Public Property Height As Single

        Public Sub New(wght As Single, hght As Single)
            Weight = wght
            Height = hght
        End Sub
    End Class
Related Posts Related QUESTIONS :
  • In SignalR Core using ChannelWriter: Do I need to call TryComplete twice if there's an exception?
  • C# GetProcessesByName: issue with colon
  • c# wpf | create complex object with user-defined name to Serialize into JSON
  • How can I get a instance of a generic list with reflection?
  • WPF XAML - Design time and visibility of textbox
  • EF Core and MySql query is too slow
  • Getting Registered App Display Name from an App Id
  • How to get all variables from a string
  • Delete entity with all childs connected
  • Azure Build agent cant´t find class library referance
  • Initialize Nested Dictionaries in c#
  • .Net Core Binding
  • Generic event test method, preventing code duplication
  • How do I keep the ellipses in the center when the screen is resized
  • How to require a property using JsonSchema.NET?
  • C# XDocument Element/Elements returns null
  • Autofac keyed service with IEnumerable relationship type
  • Installing EntityFramework via NuGet manager
  • Always Check if there is Internet Connection Xamarin forms
  • WCF OneWay service slows down when aspNetCompatibilityEnabled is set to false
  • Can we use JsonRequestBehavior.AllowGet with [HttpPost] attribute?
  • How to customize the Setup wizard with custom forms in Visual Studio setup project
  • C# ASP.NET - Use method from another class to create labels
  • C# List IList or IEnumerable as argument
  • Parsing File with C# And Replace method
  • Losing special unicode characters in encryption (C#)
  • Getting stored procedure returned value instead of row affected
  • How can I construct HTML using NameValuePair in android?
  • Loading a pop up page in ASP.net through a js file
  • How to pass alert or notification message from controller to View?
  • C# to pause, turn on ssas server, backup cube.... how to?
  • How to execute DataTable.Select() for a column of custom class type for a particular element in that C#
  • how to connect mysql8.0 with C#
  • Passing incorrect values into MultiValueConverter by MultiBinding
  • Can i use IEnumerator as Update func?
  • How to convert API Json response to C# Array?
  • Blazor Textfield Oninput User Typing Delay
  • Performing both layout and render transform results in wrong output
  • uwp beforetextchanged cursor moving in front of text
  • How to keep duplicates from a string[] exclude words from a List and print them out
  • .Net Core Strings.Asc/Mid/Chr/Len missing even after importing Microsoft.VisualBasic
  • How to return to previous search page without being asked to Confirm Form Re-submission and keeping the results on ASP.N
  • How set a identity scaffolding item/page how initial page in asp.net MVC core?
  • LINQ isn't calling Dispose on my IEnumerator when using Union and Select, expected behavior or bug?
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com