[Solved] How to implement currency conversion

Please change you code with below code [WebMethod] public decimal ConvertGOOG(decimal amount, string fromCurrency, string toCurrency) { WebClient web = new WebClient(); string apiURL = String.Format(“http://finance.google.com/finance/converter?a={0}&from={1}&to={2}”, amount, fromCurrency.ToUpper(), toCurrency.ToUpper()); string response = web.DownloadString(apiURL); var split = response.Split((new string[] { “<span class=bld>” }), StringSplitOptions.None); var value = split[1].Split(‘ ‘)[0]; decimal rate = decimal.Parse(value, CultureInfo.InvariantCulture); return rate; … Read more

[Solved] How does one elegantly provide try-catch functionality to functions and methods which are listed within an array and are about to be executed/invoked?

The functions are not being executed “automatically,” they’re being executed because you’re explicitly calling them: const arr = [ { ‘Some text’: this.f(‘a’) }, // ^^^^^^^^^^^−−−−−−−−−−−−−− here { ‘Some other text’: this.f(‘b’) } // ^^^^^^^^^^^−−−−−−−− and here ] The result of the above is an array with two objects in it, where the first object … Read more

[Solved] Python if and else

You don’t want to use the function random.choice in your if statement. Save the random name as a variable and check it. import random random_choice = [‘Noob’, ‘Average’, ‘Pro’, ‘Expert’] name = input(‘What is your gamername? ‘) random_name = random.choice(random_choice) print(name, ‘is a’, random_name, ‘Gamer’) if random_name == ‘Noob’: print(‘Im afraid there is nothing to … Read more

[Solved] Trying to calculate age in C

Expressions in C are not formulas. This: int age = CurrentYear – BornYear; Does not mean that the value of age will always be CurrentYear – BornYear. It means that at that point in the code, age is set to CurrentYear – BornYear based on the current value of those variables. Both of those variables … Read more

[Solved] Inconsistency with else statements?

First off, note that if and else always apply to the single statement that follows them. You can use { } to group multiple statements into a single compound statement, but the conditional then applies to the single { … } statement. Consider these two equivalent statements: if (foo) { bar(); } if (foo) bar(); … Read more

[Solved] Uploading a file to Google Signed URL with PHP cURL

this is what you want: remove CURLOPT_POSTFIELDS altogether, and replace CURLOPT_CUSTOMREQUEST=>’PUT’ with CURLOPT_UPLOAD=>1 and replace ‘r’ with ‘rb’, and use CURLOPT_INFILE (you’re supposed to use INFILE instead of POSTFIELDS), $fp = fopen($_FILES[‘file’][‘tmp_name’], “rb”); curl_setopt_array($ch,array( CURLOPT_UPLOAD=>1, CURLOPT_INFILE=>$fp, CURLOPT_INFILESIZE=>$_FILES[‘file’][‘size’] )); This works when I had $file = fopen($temp_name, ‘r’); never use the r mode, always use the … Read more

[Solved] Best way to echo variable in PHP [closed]

I don’t think you need 3 queries. One should be fine selecting both values. Queries 2 & 3 are identical anyway. $result1 = mysqli_query($con,”SELECT company_id, closed_state FROM tbl_company WHERE company_id=’$company_id'”) or die(mysql_error()); while($row = mysqli_fetch_array($result1)){ if ($row[‘closed_state’] == “yes”){ echo ‘<a href=”https://stackoverflow.com/questions/30514499/customers_open.php?company_id=”.$row[‘company_id’].'”>Reopen account</a>’; }else{ echo ‘<a href=”customers_close.php?company_id=’.$row[‘company_id’].'”>Close account</a>’; } } 1 solved Best way to … Read more