Questions tagged [negative-number]

A negative number is a number that is less than 0. It is signified by a preceding hyphen (i.e. -12,345).

This tag should be used for any questions dealing specifically with negative numbers.

599 questions
-2
votes
5 answers

Return a negative value

I'm trying to implement a function where I have 2 players and their payoffs depends on their actions. def game(action1,action2): if action1 == "a" and action2 == "a": payoff1 = 1 payoff2 = 1 elif action1 == "a" and action2 == "b": …
user3085433
  • 43
  • 2
  • 10
-2
votes
4 answers

python remove leading negative sign in string

I want to test if a string has a negative leading character, and then delete that character if True. I've tried: value_a = "-50.1342" temp_a = value_a.split(".") #needed for other purposes if temp_a[0].startswith('-'): del temp_a[0] print…
Yafim Simanovsky
  • 531
  • 7
  • 26
-2
votes
1 answer

Python negative values in variables in multiplication

I'm working on a program from Guttag's book, specifically altering the code from page 33 to work with negative numbers. The program is trying to find the square root of a number by using bisection search. My problem in short: >>>…
Pyth0n N00b
  • 9
  • 1
  • 1
  • 1
-2
votes
3 answers

Regex, positive or negative int not preceding by 0 or minus

I want to create a filter which checks if typed value is expected. Allowed are negative and positive (without '+' sugn) numbers not preceding by zero. Also negative sign itself is allowed. Problem is I can do search of negative number but I don't…
rainbow
  • 1,161
  • 3
  • 14
  • 29
-2
votes
2 answers

java negative double to the power of a pos/neg double

i am trying to use an exponential to work out the distance the z coordinate would be on screen from the basic z coordinate the object is, as the further away the object is the slower the object moves away and vice versa when the object is coming…
Green.jab
  • 7
  • 3
-2
votes
1 answer

Logic concerning negative num inputs being converted to positive num inputs

Maybe I'm asking google all the wrong questions but I scoured the internet and could not find posts similar to my unique problem. This is a simple coding challenge from FreeCodeCamp: I need to work on the function abTest(a,b) where when a OR b is…
-2
votes
4 answers

sum of negative int in list

I am trying to add all of the negative integers in a user input list, but the function always returns 0 as the answer. It works if I include the list as part of the function, but not when its user input. The code I have is: def…
user5514218
  • 11
  • 1
  • 1
  • 1
-2
votes
2 answers

Why do I get 0 when I print the result of fraction in C?

I have something like this in my code: a = -2; b = 1/a; printf("%d", b); The printf is printing 0. Does anyone know why this is? And what do I do to get -0.5? I also tried "%.2f" and that gave me 0.00. Thanks
Chibuikem
  • 45
  • 5
-2
votes
1 answer

Push into negative array

Is there a way to push values into a negative array? Lets say I'm doing something like this... my @arr; push (@arr, "one"); push (@arr, "two"); push (@arr, "three"); $arr[-1] = "neg_one"; $arr[-2] = "neg_two"; $arr[-3] = "neg_three"; for (my…
Ryan Dunphy
  • 792
  • 2
  • 10
  • 33
-2
votes
1 answer

How do you compare numbers greater than 9 or negative in NASM/MASM assembly?

I'm allowed to use the C functions printf, scanf, and puts. I get a number from the user (which is easy), but I need to check to see if it's less than 0 or greater than 255? I know how to compare single digit numbers but am stuck on how to compare…
Coder4Lyfe
  • 23
  • 4
-2
votes
2 answers

Integer.parseInt("-1") result an error

I'm writing new accounting program for my customer on Android,In some case I need to convert text of EditText to integer,but when I want to parse "-1" the java.lang.NumberFormatException occured! for understanding my problem try this: int i =…
Yashar Aliabbasi
  • 2,663
  • 1
  • 23
  • 35
-2
votes
1 answer

If Statement? Don't add numbers into total variable if they are negative

Question, how do I make it so when an user-inputted number is negative, it isn't added to the total variable that will be ouput? Code below! function lab10logicInLoopsPart1() { lCounter = 1; var total = 0; userNumber = 0; while(lCounter < 6)…
-3
votes
1 answer

if-else-if: getting an unexpected negative output

So i have this program, where when I select the area and type, the DP will generate. The problem is, when I select another type (tipe-45 and tipe-54), the result is showed in minus. What is the problem? if(rb1.isSelected() && t1.isSelected()){ …
HERI
  • 13
  • 1
-3
votes
1 answer

How to take in a list of numbers with negative signs?

I tried this but it gave me this error: SyntaxError: illegal expression for augmented assignment. The input will be something like this: -2 4 -1 x_forces, y_forces, z_forces = 0 x_forces, y_forces, z_forces += map(int, input().split(' '))
-3
votes
2 answers

Multiplying adjacent elements and compare which has a higher value

I am trying to compare which has a greater quotient when multiplying adjacent elements: public static void main(String args[]) { int[] inputArray = {-5, 8, -9, 1, -5, 4}; int x = 0; long maxsofar = 0; while (x < inputArray.length -…
George
  • 11
  • 3
1 2 3
39
40