Year Converter Function

i'm trying to make a function where you input a year, and the output return the centure that year is from. I got most of down, but somewhere in the logic i'm missing something and i'm not getting the correct values for when the year is, i.e. 2000 (20...
more »

2017-03-19 22:03 (2) Answers

Python - rounding to the nearest integer

I've been trying to figure this out for ages but with no luck. I need to round each coefficient to the nearest integer. To do this I introduce a small number dq=0.0001. If a[0]=0.5, then round(a[0]) = 0.0; this is clearly not good. However, to work...
more »

2017-03-19 09:03 (3) Answers

How to read multiple digit number from a string

I am trying to pass a string S as input. Here the string S can contain multiple integer values followed by an alphabet. The program must expand the alphabets based on the previous integer value. Consider the Input: 4a5h For which the Output: aaaahhh...
more »

2017-03-18 18:03 (3) Answers

Integer.parseInt: 0xff80CBC4 is an invalid int

Can somebody please explain why the second and the third of the following statements fail? Integer myColor = 0xff80CBC4 //works Integer.parseInt("0xff80CBC4".substring(2), 16) //does not work Integer.decode("0xff80CBC4") //does not work When run,...
more »

2017-03-18 16:03 (3) Answers

Visible Deprecation Warning Python

I am trying to make a model in python for an economics dissertation and in calculating a function: elif wage_online == max(wages): # after going to online you get the highest wage after cost of education learning_benefit = i...
more »

2017-03-17 21:03 (1) Answers

Convert a String to a Number Only

I read in two numbers from a user but the number is a string. #!/bin/bash read -p "Enter first number: " num1 read -p "Enter second number: " num2 I know you can use the the "expr" or "bc" command to automatically convert the string to a number th...
more »

2017-03-17 16:03 (0) Answers

range() funtion as an integer

I have a code as follows: if records[rec][4]+6 > records[0:len(records)][4] > records[rec][4]-6 The [0:len(records)] is the issue, as I would like to express the range as an integer. As I have to use Python-2.4 range(), xrange() and a func...
more »

2017-03-15 14:03 (0) Answers

Swift For Loops using Closed Range

I have a for loop and want to access the 'current' index. Xcode is giving me irritating errors. for k in [] { map.returns.append((map.closingPrices[k]-map.closingPrices[k-1])/map.closingPrices[k-1]) } So wh...
more »

2017-03-14 19:03 (1) Answers

Delphi: "Incompatible types Integer and Extended"

I currently face the problem of not being able to divide my ClientWidth by 2 (or multiply with 0.5 because of the error message Delphi is giving me: [Error] Unit1.pas(59): Incompatible types: 'Integer' and 'Extended' [Error] Unit1.pas(60): Incompati...
more »

2017-03-13 18:03 (2) Answers

Issue with input number when number has .0

Got issue when trying to validate the input type number. I want to accept integers only. Don't want to accept float (it almost works). Got issue with number like 1.0, 3.0, but not with 1.1 When doing _.toNumber it change 1.0 to 1 but still I want t...
more »

2017-03-13 12:03 (1) Answers

why sizeof(0xF) is 4 bytes?

I have following code, unsigned short code = 0x12E0; code = code & 0x0FFF; In my CLion IDE, i am getting a warning that "Values of type int may not fit into the receiver type unsigned short" If I put it like code &= 0x0FFF;, the war...
more »

2017-03-13 12:03 (3) Answers

Integer-restricted only?

How can I limit the input to only integers (no doubles etc)? simple question for someone experienced to answer. if input is anything other than double then display error message, with ability to enter input again import java.util.Scanner; public s...
more »

2017-03-11 23:03 (2) Answers