static void Main(string[] args) { var isRunning = true; models.Calculator calc = new models.Calculator(); Console.WriteLine("welcome to our calculator"); while (isRunning) { Console.WriteLine("Start your calculation."); Console.WriteLine("number 1:"); string number1Input = Console.ReadLine(); Console.WriteLine("number 2:"); string number2Input = Console.ReadLine(); Console.WriteLine("operation:"); string operation = Console.ReadLine(); decimal.TryParse(number1Input, out var number1); decimal.TryParse(number2Input, out var number2); CalculationType?calculationType = null; switch (operation) { case "+": calculationType = CalculationType.ADDITION; break; case "-": calculationType = CalculationType.SUBTRACTION; break; case "*": calculationType = CalculationType.MULTIPLICATION; break; case "/": calculationType = CalculationType.DIVISTION; break; } if (calculationType.HasValue) { Console.WriteLine(calc.Calculate(number1, number2, calculationType.Value)); } Console.WriteLine("Do you want to continue? y/n"); string choice = Console.ReadLine(); if (choice.ToLower().Equals("n")) { isRunning = false; } } }
/// <summary> /// Calculates a result using given numbers a and b according to the given calculation type. /// </summary> /// <param name="a">The first argument.</param> /// <param name="b">The second argument.</param> /// <param name="calculationType">The calculation type to perform. For example Add, Subtract.</param> /// <returns>The calculated result.</returns> public static double Calculate(double a, double b, CalculationType?calculationType) { switch (calculationType) { case CalculationType.Add: return(a + b); case CalculationType.Subtract: return(a - b); case CalculationType.Divide: return(a / b); case CalculationType.Multiply: return(a * b); default: throw new ArgumentException("calculationType is required!"); } }
public static void GeneratePurchaseInvoiceFromMultipleSalesOrders(XElement source, CommercialDocument destination) { /* * robimy fakture zakupową na pozycje usługowe */ DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>(); List <CommercialDocument> soDocs = new List <CommercialDocument>(); CalculationType?calcType = CalculationType.Net; destination.CalculationType = calcType.Value; foreach (XElement soId in source.Elements("salesOrderId")) { Guid docId = new Guid(soId.Value); var exists = soDocs.Where(d => d.Id.Value == docId).FirstOrDefault(); if (exists != null) { continue; } CommercialDocument doc = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, docId); soDocs.Add(doc); } //kopiujemy atrybuty jezeli sa jakies takie DuplicableAttributeFactory.DuplicateAttributes(soDocs, destination); XElement tagXml = new XElement("salesOrders"); foreach (CommercialDocument salesOrder in soDocs) { //Dla dokumentu zakupowego nie ma ograniczenia //if (salesOrder.Relations.Where(rr => rr.RelationType == DocumentRelationType.SalesOrderToInvoice).FirstOrDefault() != null) // throw new ClientException(ClientExceptionId.UnableToCreateInvoiceToSalesOrder, null, "orderNumber:" + salesOrder.Number.FullNumber); SalesOrderFactory.CopyLinesFromSalesOrder(salesOrder, destination, true, false, true, false); tagXml.Add(new XElement("salesOrder", new XAttribute("id", salesOrder.Id.ToUpperString()), new XAttribute("version", salesOrder.Version.ToUpperString()))); } destination.Calculate(); destination.Tag = tagXml.ToString(SaveOptions.DisableFormatting); }
static void Main(string[] args) { Console.WriteLine(Enum.GetName(typeof(CalculationType), CalculationType.ADDITION)); models.Calculator calc = new models.Calculator(); Console.WriteLine("Welcome to our calculator"); Console.WriteLine("Number 1:"); string number1Input = Console.ReadLine(); Console.WriteLine("Number 2:"); string number2Input = Console.ReadLine(); Console.WriteLine("Operation (-,+,*,/):"); string operation = Console.ReadLine(); decimal.TryParse(number1Input, out var number1); decimal.TryParse(number2Input, out var number2); CalculationType?calculationType = null; switch (operation) { case "+": calculationType = CalculationType.ADDITION; break; case "-": calculationType = CalculationType.SUBTRACTION; break; case "*": calculationType = CalculationType.MULTIPLICATION; break; case "/": calculationType = CalculationType.DIVISTION; break; } if (calculationType.HasValue) { Console.WriteLine(calc.Calculate(number1, number2, calculationType.Value)); } }
static void Main(string[] args) { Calculator calc = new Calculator(); Console.WriteLine("Taschenrechner App"); Console.Write("1. Zahl: "); string val1Input = Console.ReadLine(); Console.Write("2. Zahl: "); string val2Input = Console.ReadLine(); Console.Write("Operator: "); string operation = Console.ReadLine(); decimal.TryParse(val1Input, out var number1); decimal.TryParse(val2Input, out var number2); CalculationType?calculationType = null; switch (operation) { case "+": calculationType = CalculationType.Addition; break; case "-": calculationType = CalculationType.Subtraction; break; case "*": calculationType = CalculationType.Multiplication; break; case "/": calculationType = CalculationType.Division; break; } if (calculationType.HasValue) { Console.WriteLine(calc.Calculate(number1, number2, (CalculatorProject.CalculationType)calculationType.Value)); } }
public static Uri PriceHistorical( string fsym, IEnumerable <string> tsyms, IEnumerable <string> markets, DateTimeOffset ts, CalculationType?calculationType, bool?tryConversion) { return(new Uri(MinApiEndpoint, "pricehistorical").ApplyParameters( new Dictionary <string, string> { { nameof(fsym), fsym }, { nameof(tsyms), tsyms.ToJoinedList() }, { nameof(ts), ts.ToUnixTime().ToString(CultureInfo.InvariantCulture) }, { nameof(markets), markets?.ToJoinedList() }, { nameof(calculationType), calculationType?.ToString("G") }, { nameof(tryConversion), tryConversion?.ToString() } })); }
/// <summary> /// Get the price of any cryptocurrency in any other currency that you need at a given timestamp. /// The price comes from the daily info - so it would be the price at the end of the day GMT based on the requested TS. /// If the crypto does not trade directly into the toSymbol requested, BTC will be used for conversion. /// Tries to get direct trading pair data, if there is none or it is more than 10 days before the ts requested, it uses BTC conversion. /// If the oposite pair trades we invert it (eg.: BTC-XMR)The calculation types are: Close - a Close of the day close price,MidHighLow - the average between the 24 H high and low.VolFVolT - the total volume to / the total volume from. /// </summary> /// <param name="fromSymbol">from symbol.</param> /// <param name="toSymbols">to symbols.</param> /// <param name="markets">(Optional) Exchange name default => CCCAGG.</param> /// <param name="requestedDate">The requested date.</param> /// <param name="calculationType">(Optional) Type of the calculation.</param> /// <param name="tryConversion">(Optional) If set to false, it will try to get values without /// using any conversion at all (defaultVal:true)</param> /// <seealso cref="M:CryptoCompare.Clients.IPricesClient.Historical(string,IEnumerable{string},DateTimeOffset,CalculationType?,bool?,string)"/> public async Task <PriceHistoricalReponse> HistoricalAsync( [NotNull] string fromSymbol, [NotNull] IEnumerable <string> toSymbols, DateTimeOffset requestedDate, IEnumerable <string> markets = null, CalculationType?calculationType = null, bool?tryConversion = null) { Check.NotNullOrWhiteSpace(fromSymbol, nameof(fromSymbol)); Check.NotEmpty(toSymbols, nameof(toSymbols)); return(await this.GetAsync <PriceHistoricalReponse>( ApiUrls.PriceHistorical( fromSymbol, toSymbols, markets, requestedDate, calculationType, tryConversion)).ConfigureAwait(false)); }
public static Uri DayAveragePrice( string fsym, string tsym, string e, DateTimeOffset?toTs, CalculationType?avgType, int?UTCHourDiff, bool?tryConversion) { return(new Uri(MinApiEndpoint, "dayAvg").ApplyParameters( new Dictionary <string, string> { { nameof(fsym), fsym }, { nameof(tsym), tsym }, { nameof(e), e }, { nameof(toTs), toTs?.ToString() }, { nameof(avgType), avgType?.ToString() }, { nameof(UTCHourDiff), UTCHourDiff?.ToString() }, { nameof(tryConversion), tryConversion?.ToString() }, })); }
private void Button_Click(object sender, RoutedEventArgs e) { string content = (string)(sender is Button ? ((Button)sender).Content : sender); switch (content) { case "+": calculationTypeChosen = CalculationType.Add; break; case "-": calculationTypeChosen = CalculationType.Subtract; break; case "/": calculationTypeChosen = CalculationType.Divide; break; case "x": calculationTypeChosen = CalculationType.Multiply; break; case "c": inputs = new string[2]; calculationTypeChosen = null; showingResult = false; InputDisplay.Content = ""; break; case "=": if (calculationTypeChosen == null) { return; } InputDisplay.Content = CalculatorClass.Calculate(Convert.ToDouble(inputs[0], cultureInfo), Convert.ToDouble(inputs[1], cultureInfo), calculationTypeChosen); showingResult = true; break; default: if (showingResult) { Button_Click("c", new RoutedEventArgs()); } inputs[calculationTypeChosen != null ? 1 : 0] += content; InputDisplay.Content = inputs[calculationTypeChosen != null ? 1 : 0]; break; } }
public async Task <HistoryDayAverageResponse> DayAveragePriceAsync( string fromSymbol, string toSymbol, string?exchangeName = null, DateTimeOffset?toDate = null, CalculationType?avgType = null, int?utcHourDiff = null, bool?tryConversion = null) { Check.NotNullOrWhiteSpace(toSymbol, nameof(toSymbol)); Check.NotNullOrWhiteSpace(fromSymbol, nameof(fromSymbol)); return(await this.GetAsync <HistoryDayAverageResponse>( ApiUrls.DayAveragePrice( fromSymbol, toSymbol, exchangeName, toDate, avgType, utcHourDiff, tryConversion)).ConfigureAwait(false)); }
private void SaveDecision(CalculationType?type) { LastResultType = type; Close(); }
public ApiCalculationMetadataBuilder WithCalculationType(CalculationType calculationType) { _calculationType = calculationType; return(this); }
public TemplateCalculationBuilder WithType(CalculationType type) { _type = type; return(this); }
public CalculationBuilder WithCalculationType(CalculationType calculationType) { _calculationType = calculationType; return(this); }
public static void GenerateInvoiceFromMultipleSalesOrders(XElement source, CommercialDocument destination) { /* * <source type="multipleSalesOrders"> * <salesOrderId>{documentId}</salesOrderId> * <salesOrderId>{documentId}</salesOrderId> * <salesOrderId>{documentId}</salesOrderId> * ......... * </source> */ DocumentMapper mapper = DependencyContainerManager.Container.Get <DocumentMapper>(); List <CommercialDocument> soDocs = new List <CommercialDocument>(); CalculationType?calcType = null; foreach (XElement soId in source.Elements("salesOrderId")) { Guid docId = new Guid(soId.Value); var exists = soDocs.Where(d => d.Id.Value == docId).FirstOrDefault(); if (exists != null) { continue; } CommercialDocument doc = (CommercialDocument)mapper.LoadBusinessObject(BusinessObjectType.CommercialDocument, docId); soDocs.Add(doc); if (calcType == null) { calcType = doc.CalculationType; } else if (calcType.Value != doc.CalculationType) { throw new ClientException(ClientExceptionId.DifferentCalculationTypes); } } if (calcType.Value != destination.CalculationType && destination.DocumentType.CommercialDocumentOptions.AllowCalculationTypeChange) { destination.CalculationType = calcType.Value; } //sprawdzamy czy dok. zrodlowe maja wspolnego kontrahenta. jezeli tak to kopiujemy go na fakture bool copyContractor = true; //jezeli gdzies nie ma kontrahenta to nie kopiujemy var emptyContractor = soDocs.Where(w => w.Contractor == null).FirstOrDefault(); if (emptyContractor != null) { copyContractor = false; } if (copyContractor) { var differentContractor = soDocs.Where(ww => ww.Contractor.Id.Value != soDocs[0].Contractor.Id.Value).FirstOrDefault(); if (differentContractor != null) { copyContractor = false; } } if (copyContractor) { destination.Contractor = soDocs[0].Contractor; if (destination.Contractor != null) { var address = destination.Contractor.Addresses.GetBillingAddress(); if (address != null) { destination.ContractorAddressId = address.Id.Value; } } } //kopiujemy atrybuty jezeli sa jakies takie DuplicableAttributeFactory.DuplicateAttributes(soDocs, destination); XElement tagXml = new XElement("salesOrders"); foreach (CommercialDocument salesOrder in soDocs) { if (salesOrder.Relations.Where(rr => rr.RelationType == DocumentRelationType.SalesOrderToInvoice).FirstOrDefault() != null) { throw new ClientException(ClientExceptionId.UnableToCreateInvoiceToSalesOrder, null, "orderNumber:" + salesOrder.Number.FullNumber); } SalesOrderFactory.CopyLinesFromSalesOrder(salesOrder, destination, true, false, true, true); tagXml.Add(new XElement("salesOrder", new XAttribute("id", salesOrder.Id.ToUpperString()), new XAttribute("version", salesOrder.Version.ToUpperString()))); } destination.Calculate(); destination.Tag = tagXml.ToString(SaveOptions.DisableFormatting); }
/// <summary>Historical Day OHLCV for a timestamp</summary> /// <param name="tryConversion">If set to false, it will try to get only direct trading values</param> /// <param name="fsym">The cryptocurrency symbol of interest</param> /// <param name="tsyms">Comma separated cryptocurrency symbols list to convert into</param> /// <param name="e">The exchange to obtain data from (our aggregated average - CCCAGG - by default)</param> /// <param name="ts">The unix timestamp of interest</param> /// <param name="calculationType">Type of average to calculate (Close - a Close of the day close price, MidHighLow - the average between the 24 H high and low, VolFVolT - the total volume to / the total volume from)</param> /// <param name="extraParams">The name of your application (we recommend you send it)</param> /// <param name="sign">If set to true, the server will sign the requests (be default we don't sign them), this is useful for usage in smart contracts</param> /// <returns>Status 200</returns> /// <exception cref="SwaggerException">A server side error occurred.</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public System.Threading.Tasks.Task <System.Collections.Generic.Dictionary <string, System.Collections.Generic.Dictionary <string, double> > > PricehistoricalAsync(bool?tryConversion, string fsym, string[] tsyms, string e, int?ts, CalculationType?calculationType, string extraParams, bool?sign, System.Threading.CancellationToken cancellationToken) { return(PricehistoricalAsync(tryConversion, fsym, BuildList(tsyms), e, ts, calculationType, extraParams, sign, cancellationToken)); }