Calculator for Addition 3 private double data members with three public properties
Calculator for Addition 3 private double data members with three public properties
Calculator Version 1
Create a Console project.
Rename "Program.cs" to "CalculatorRun.cs"
Add class "Calculator.cs"
- 3 private double data members with three public properties
- firstOperand, FirstOperand;
- secondOperand, SecondOperand;
- result, Result;
In "CalculatorRun.cs", have users to enter values for firstOperand and secondOperand,
show addtion result.
I have worked on this for hours and it makes no sense still. My code is useless. Does anyone have input?
This is what I have:
namespace CalculatorRun
class Calculator
static void Main(string args)
decimal FirstOperand, SecondOperand, Result, result;
Console.Write("Addition Calculation");
Console.Write(" nn");
Console.Write(" Enter first operand: ");
FirstOperand = Convert.ToDecimal(Console.ReadLine());
Console.Write(" Enter second operand: ");
SecondOperand = Convert.ToDecimal(Console.ReadLine());
Console.Write("-------------------------nn");
Result = FirstOperand + SecondOperand;
result = Convert.ToDecimal(Result);
Console.WriteLine("Addition Result: 0", string.Format("0", result));
Console.WriteLine("Press any key to continue.....");
Console.ReadLine();
But it needs to be more like this (of course using the directions at the top). But when I have tried it, I can't get it to work. :
using System;
namespace Calculator
class Program
public static void Main(string args)
//<-----------
public int number01;
public int number02;
public int Number03
get
return number02 / number01;
//<----------
class Program1 : Program
public void DivideFinal()//<---- void not int
Console.Write("Enter a number to be divided: ");
Console.ReadKey();
number01 = Convert.ToInt32(Console.ReadKey());
Console.WriteLine("Enter another number to be divided");
number02 = Convert.ToInt32(Console.ReadKey());
Console.WriteLine("The result is: " + Number03);
Console.ReadKey();
I apologize. I updated it.
– irrevocably
Sep 10 '18 at 1:46
your code is confusing. Program1 inherits from Program. why?
– Gauravsa
Sep 10 '18 at 2:06
addition code seems to be working. what is not working here?
– Gauravsa
Sep 10 '18 at 2:09
My biggest issue is I don't understand how to add the requirements he wants, as wanting a public and private and a get and return because it seems to not be needed when just using only addition. So what I am missing is (for example only) public int number01; public int number02; public int Number03 get return number02 / number01;
– irrevocably
Sep 10 '18 at 2:11
1 Answer
1
This will do it for you. Explanation in comments:
using System;
namespace ConsoleApplication1
class Program
static void Main( string args )
Calculator calculator = new Calculator();
Console.Write( " Enter first operand: " );
calculator.FirstOperand = Convert.ToDouble( Console.ReadLine() ); //get the first
Console.Write( " Enter first operand: " );
calculator.SecondOperand = Convert.ToDouble( Console.ReadLine() ); //get the second
calculator.Addition(); //Do addition
Console.WriteLine( "Addition Result: 0", calculator.Result ); //show result
Console.WriteLine( "Press any key to continue....." );
Console.ReadLine();
class Calculator
private double firstOperand, secondOperand, result; //double data members
//3 public properties
public double FirstOperand
get return firstOperand;
set firstOperand = value;
public double SecondOperand
get return secondOperand;
set secondOperand = value;
public double Result
get return result;
set result = value;
//1 public method Addition()
public double Addition()
return result = firstOperand + secondOperand;
Severity Code Description Project File Line Suppression State Error CS1513 expected ConsoleApp2 C:UsersSamsungTouchDesktopSchoolC#AssignmentsCalculatorRun3ConsoleApp2ConsoleApp2Program.cs 57 Active
– irrevocably
Sep 10 '18 at 2:42
@irrevocably You probably missed a curly bracket
}. The above code is inside a name space– γηράσκω δ' αεί πολλά διδασκόμε
Sep 10 '18 at 2:48
}
Thank you so much! I believe that is correct. I edited it a little bit so the first "program" is "calculator run"
– irrevocably
Sep 10 '18 at 2:49
@irrevocably don't forget to mark this answer as correct if it is.
– John Ephraim Tugado
Sep 10 '18 at 3:18
@JohnEphraimTugado Thank you for walking me through my first question! I learned a lot about how Stack Overflow works and you were really nice about it. I will make sure to do better next time. γηράσκω δ' αεί πολλά διδασκόμε Thank you so much for your answer, I had been working on this for over 10 hours and was in tears! It looks so simple, but for someone who is new the wording of the assignment had me so confused I was so worried I was doing it wrong. Thank you for the clarification! Also, thank you to everyone for your input you all helped tremendously! What a wonderful community.
– irrevocably
Sep 10 '18 at 13:35
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How can we provide an input if you didn't post your code? Here in SO you must be specific when asking questions so that it won't get closed.
– John Ephraim Tugado
Sep 10 '18 at 1:38