int

Can't convert a number to a float

末鹿安然 提交于 2019-12-24 20:05:16
问题 I'm trying to solve a homework problem as an extreme novice to python, and I don't understand what I'm doing wrong. I have the code and error message below, hoping that someone can tell me where I went wrong. The miles input tries 10, 50, then 100. Which works. Mpg is 20.0. Also works. gp input is 3.1599, which gives me this error. Not sure why. miles = float(input()) mpg = float(input()) gp = float(input()) price = (miles*1.0/mpg)*gp print(price) Traceback (most recent call last): File "main

Objective-C: How do you declare and retain an int?

江枫思渺然 提交于 2019-12-24 19:54:22
问题 Here's my code: @interface Game : Layer // this is from cocos2d { int maxSprites; } @implementation Game -(void)initVariables { maxSprites = 18; } Later on, when I print it out, NSLog(@" maxSprites = %d ", maxSprites); I get: maxSprites = 2 And operations that require it to be 18, crash or don't work, as if it's really just 2 now. How would that be possible? =) APPLE + SHIFT + F reveals no other usage of the maxSprites variable. I've looked at other code examples and often they're exposing

Displaying parameters of method in a textview or toast

元气小坏坏 提交于 2019-12-24 19:46:42
问题 Hey guys i cannot figure out the logic behind why my code is not working, apparently I am not allowed to print out these values in this way. I cannot display the values of v1,v2,v3 or v4 into a toast or a textfield, but i can display strings. Am i calling these values wrong? If you need me to post more code let me know. testWheelValue(R.id.passw_1, v1); testWheelValue(R.id.passw_2, v2); testWheelValue(R.id.passw_3, v3); testWheelValue(R.id.passw_4, v4); testpins = v1 + v2 + v3 + v4; text

PHP equivalent of C code from Bit Twiddling Hacks?

为君一笑 提交于 2019-12-24 16:58:10
问题 http://www-graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel v = v - ((v >> 1) & (T)~(T)0/3); // temp v = (v & (T)~(T)0/15*3) + ((v >> 2) & (T)~(T)0/15*3); // temp v = (v + (v >> 4)) & (T)~(T)0/255*15; // temp c = (T)(v * ((T)~(T)0/255)) >> (sizeof(v) - 1) * CHAR_BIT; // count This is the same problem in Python: Python equivalent of C code from Bit Twiddling Hacks? I need to use this code in PHP, independently from integer size (the above code works up to 128-bit integers,

Input faster than scanf for int in c/c++

让人想犯罪 __ 提交于 2019-12-24 16:41:20
问题 Hello everyone, I am solving a problem in a coding competition in which i have to give very large input. As stated int the problem - The input file size could reach almost 8MB so be sure you are using fast I/O method. The input is to be given as number of test cases. Then the dimension n of the square matrix. and then the whole matrix as 2 3 2 6 4 4 8 9 7 9 4 2 8 4 15 4 I have got a code from somewhere on net but i don't think that it is doing any help because with this also i am getting

scanf and keeping char as an integer

浪子不回头ぞ 提交于 2019-12-24 16:35:18
问题 I just can't get it. Char is an integer, right? So I can do int var; scanf("%d", &var); I:[65] printf("%c", var); o:[A]. Why is then wrog to do: char var; scanf("%d", &var); I:[A] printf("%d", var) O:[-1236778] 回答1: In the second scanf() scanf("%d", &var); the scanf() parsed the print directive %d . This implies that the argument &var is expected to be the address to an int . Instead the address to a char was given. The size of an int is certainly larger than the size of a char . As scanf()

Why is 017 == 15 in C?

こ雲淡風輕ζ 提交于 2019-12-24 15:47:30
问题 I've done a little bit of reading on endianness and its role in C, but nothing has really managed to clarify this for me. I'm just starting out with C and I saw this example: #include <stdio.h> int main(void) { int x = 017; int y = 12; int diff = x - y; printf("diff is %d\n", diff); return 0; } and it asks what will print. I compiled and ran the example and got that diff is 3, so x is 15. I sort of see why this is, but would really appreciate if somebody really clarified it for me. [1] I've

PowerShell force [int] to wrap (IP to Long conversion)

这一生的挚爱 提交于 2019-12-24 15:23:03
问题 Just a quick question as I'm kind of new to math in PowerShell I need to make a converter in PowerShell that converts IP to Long. It works fine for lower values, but on higher ones it is causing an Integer Overflow. [int]$a = Read-Host "First bit of IP address" [int]$b = Read-Host "2nd bit of IP address" [int]$c = Read-Host "3rd bit of IP address" [int]$d = Read-Host "4th bit of IP address" $a *= 16777216 $b *= 65536 $c *= 256 $base10IP = $a + $b + $c + $d Write-Host $base10IP Works fine if I

Treating a string as an integer

こ雲淡風輕ζ 提交于 2019-12-24 13:42:53
问题 I'm trying to make a very simple Blackjack game. When you get dealt two cards, everything's okay if they're both integers or strings, but I get an error if the two cards dealt are a string and an integer. How can I make it so that if you get dealt a 7 and a Queen, the Queen will be treated as 10, giving you a total of 17? #imports import random Jack = 10 Queen = 10 King = 10 Ace = 1 or 11 Cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King', 'Ace'] #Faces = Jack, Queen, King, Ace

Working with large integer arrays

≡放荡痞女 提交于 2019-12-24 13:15:23
问题 How to work with large integer, do I need GMP libraries or something? I want an array that has elements starting from 0 to 2^32 How to get this to work: #include <stdio.h> int main(){ unsigned int i,j=0,sz=4294967295; unsigned int A[sz]; A[j]=0; for(i=1;i<=sz;i++){ A[i]=A[j]+1 ; j++; printf("%u\n",A[i]); } return 0; } error: process exited with return value 3221225725 is it that the array is too big or something?? 回答1: According to Google, your A array is approximately 17 gigabytes. That's a