685 questions
1
vote
1
answer
41
views
How can I use a rnd generated in a loop in an if statement
I have to write a program that simulates 2 dice rolls 4 times, if the 2 dice end up as the same number a certain multiplier needs to be increased by 10, so far I've managed to simulate dice rolls by ...
-4
votes
1
answer
721
views
I have the error CS0136, but I can't find a solution
I have an error saying: (error CS0136: A local or parameter named 'facingRight' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter). ...
0
votes
4
answers
11k
views
How to add variable inside the cout?
I want to add float average variable inside the cout.
What's the perfect way for it?
int first , second , third;
cout<<"enter the first number: ";
cin>>first;
cout<<"enter the ...
1
vote
1
answer
2k
views
How do I declare a variable based on user input?
I am trying to create a program that spell checks what the user has typed in. They have to type the word 'type' in 10 times correctly and it will display a message saying how long it took.
My problem ...
0
votes
4
answers
298
views
Java - How do I call a method within a switch statement?
averageLength gets all the words the user has entered in the previous case and gets the average amount of words. The switch statement sits under the main method (not shown here) but when I try to ...
0
votes
2
answers
47
views
How to rewrite redundant method declaration and create a shorter one?
I have declared identical const values (sort of). Here's what I have so far...
import React from 'react'
function Component_a() {
const x = 5;
const y = 10;
const image_a = [...Array(x)]....
-1
votes
1
answer
89
views
Why does different integer declaration change the results?
The problem exists in the first nested loop, where the results doesn't go out as expected, I'm working on CodeBlocks 17.12
What I did to try fix the problem is to change "int s[n]" to "long long s[n]"...
3
votes
3
answers
93
views
A query about class nesting in java
public class Outer{
public class Inner{
}
}
public class Main {
public static void main(String[] args) {
Outer objOut = new Outer();
//Outer.Inner object1= objOut.new ...
2
votes
3
answers
159
views
Are "constructor statement" and "declaration statement" correct names to describe these statements?
I am confused about the following Java statements:
ArtClass artClass0 = new ArtClass();
int int3 = 73;
boolean boolean0 = artClass0.foo(int3);
Is the first statement called constructor statement? For ...
3
votes
3
answers
27k
views
variable declaration (implicit and explicit and advantages & disadvantages)
"What are explicit declaration & implicit declaration of variables in programming language concepts and their advantages and disadvantages?"
0
votes
1
answer
103
views
Is static a useful modifier for a private string [duplicate]
In my team we had a small discussion if a field declared 'private static final' in a class has any advantages from just declaring it 'private final'.
For example if I have the following line in my ...
0
votes
2
answers
77
views
JavaScript - Is it okay to define a property of a previously declared object during a variable declaration?
Is it common practice (or at least syntactically valid across browsers and implementations of JS) to abuse RTL associativity of assignment operators so that one can define two variables (with the ...
10
votes
4
answers
3k
views
Should I use static variables in my functions to prevent recomputing values?
I've been writing C++ code for a while now, but there's something I've been wondering for some time, without being to find a clear answer.
My point here is the following: let's say I have a function (...
4
votes
2
answers
3k
views
Does const pointer-to-member default to pointing to an int?
While playing with pointers-to-member I encountered a behaviour that seems slightly inconsistent and somewhat counterintuitive to me. Consider the following dummy structure:
struct foo {
int x;
...
0
votes
1
answer
56
views
How can I fix this function to recursively search an object for all instances of a key?
I'm trying to traverse an object to find all instances of a key, and get any value associated with the key. (The object may have a key multiple times at different depths)
I find the value I want just ...
0
votes
1
answer
341
views
How to redeclare variables with the same name but belonging to different files in javascript?
I am loading two js files within an HTML page where both files contain the declaration of variables with the same name. I would like to know if there is a way to declare two variables with the same ...
0
votes
2
answers
86
views
C++ pointers objects difference
Can somebody explain me the difference between the following?
Those two
float *pointer[10];
float *(pointer[10]);
and those two
int(*pointer_function)();
int *pointer_function();
-1
votes
2
answers
93
views
How to change the value of a variable inside an if-statment and apply in all in python
I am creating a feature in my chat bot that changes the bot agent name. I declare the name of the bot at the top.
bot = "Bot"
Then I create a function that takes input from the user and changes the ...
-1
votes
3
answers
2k
views
foreach: why can't the element variable be declared outside?
A "foreach" in Java is, for example
for (Mouse mouse: mouses) {
[...]
}
We can't do:
Mouse mouse;
for (mouse: mouses) {
[...]
}
I quote geeksforgeeks: Since the i variable goes out of scope ...
-1
votes
1
answer
158
views
Why I can't initialize a class object when declaring it? [closed]
I have overloaded the assignment operator for a particular class and after that I soon found out a problem.
During the declaration of a class object, if I initialize it with another object that ...
1
vote
1
answer
226
views
Declaring arrays according the user input
i'm trying to declare arrays depending on the user input,
consider if user enters 2, then i need to declare 2 arrays.
like :int case1[10]={},case2[10]={},
i tried it using macros CONCAT but it didn't ...
-2
votes
1
answer
196
views
How do you define arrays of different sizes using if statements in Java?
So, I was trying to code some test cases for a Java project I'm doing, and I decided that I wanted to move them into a function of their own, and choose between them using a parameter of the test ...
-1
votes
1
answer
41
views
Why does my code doesn't work when i declare a variable outside the for loop?
I want to get the intersection of two linked lists but when i declare the iterators outside the for loop it just doesn't work
// THIS WORKS FINE
for (SList iter1 = list1 ; !slist_empty(iter1); iter1 ...
1
vote
4
answers
72
views
Differentiating various declarations in C
While I was going through my questions, I found the these questions:
1) int*p;
2) int p(char*a)
3) int(*p(char*a))
4) int *p(void)
5) int*(*p[10])(char a)
(Please correct me if I'm wrong with my ...
1
vote
1
answer
110
views
Worksheet object declaration
I've always declared a worksheet object using the syntax Dim w as Worksheet, but recently I came across some code that used Dim w as Excel.Worksheet.
I checked with the Object Browser which stated ...
3
votes
2
answers
2k
views
How can I declare a SFML window to all my class functions?
This might be a noob question, but I'm trying to make a simple player move in a 2D-grid in SFML. I'm creating a while loop for rendering what is happening, and I can get it to work, but I want to use ...
19
votes
2
answers
58k
views
How to declare multiple variables with specifying type using As in VBA?
According to this documentation by Microsoft, the following code can be used to make sure;
a, b, and c are all Single; x and y are both Double
Dim a, b, c As Single, x, y As Double, i As Integer
...
4
votes
3
answers
2k
views
Create a string variable and ask for input on the same line?
I absolutely hate these unnecessary steps in programming where you declare and assign a variable on one line and ask for an input in the next.
To keep it short, I want to create a variable and ask ...
1
vote
2
answers
135
views
How to declare a variable type depending on a ternary expression?
I have this enum :
enum WeatherMapDisplayType {
case temperature
case wind
}
Can I declare a variable like this ?
let markerView: mode == .temperature ? WeatherMapItemTemp : ...
5
votes
2
answers
2k
views
Standard to declare all javascript variables in first line of code?
We're working with a new company and they have a coding standard where they declare all Javascript variables used in a method immediately in the first line of the method.
I asked if there was a ...
-1
votes
1
answer
307
views
Why does List declaration is not working in c# [duplicate]
I am trying to declare the List like below code.
public List<string> t1,t2,t3 = new List<string>();
When I am trying to add something to List then it gives me error of was null on run ...
-2
votes
2
answers
161
views
What is the best way to declare many variables at once for a single function?
I wanted to use a function to search through a list of possible message values. E.g, a message may be '01 02 03' hex, and then I will check against possible messages if it is any of those.
What I don'...
0
votes
1
answer
843
views
Can the array variable values persist when VBA macro finishes
Can the array variable values persist when macro finishes? I have declared a global variable:
Option Explicit
Public Arr2D As Variant
Public Sub ReadDataToArr()
Arr2D = [MyNamedRange].Value
End ...
0
votes
2
answers
447
views
Storing a static variable in a temp variable
I am trying to build a chess engine as a long time project. Currently I am working on a method to flipp the board (like turning it around but changing colors as well). Uppercase letters represent ...
0
votes
1
answer
149
views
How to declare variable for DataGridviewColumn Type?
This must be simple, but I couldn't figure it out even after reading Microsoft's specification.
How do I store DataGridViewColumn type in a declared variable? It has to provide a collection of types, ...
0
votes
1
answer
231
views
Variable declaration in Swift REPL must have initial value
Studying Swift grammar declaration of closure. I'm having a problem with:
let add: (Int, Int) -> Int
add = { (a: Int, b: Int) -> Int in
return a + b
}
error:
variables currently must ...
1
vote
2
answers
181
views
Explicit variable declaration
I have a local variable implicitly defined as var, and is being populated with objects retrieved from a database through Entity Framework. When I hover over the variable I get the details as shown in ...
1
vote
1
answer
288
views
Does "< />" mean anything in Java?
Now, I know that StackOverflow is not a place to ask for help on homework, but this question has me completely stumped. I showed it to my friends and they are just as confused as I am.
I had two ...
0
votes
1
answer
32
views
Declare properties for storing column position of a line in a file
Let's say I have a text file and a line like this:
This is an example line within a file.
What I need to do is to modify this line based on a prefixed column position, and an input expectedString.
...
1
vote
2
answers
3k
views
Cannot set property 'src' of null when using variable source
I saw that this question was asked many times and I've been looking in every single one for a solution but couldn't find one for my specific problem. I'm composing a link using different strings and ...
4
votes
2
answers
7k
views
How to declare a variable in a ternary expression?
I need to set i depending on a condition:
let i = null
nightmode === true ? i = 1 : i = 0
Is it possible to declare i within the ternary expression, or does it have to be in outside of it (to handle ...
1
vote
1
answer
196
views
Multiple Inline declaration vs Reuse of variables
Having a procedure with alot of blocks of nested for-loops ex. one block
could look like this
for a := 0 to x do
//Do something
for b := 0 to x do
for c := 0 to a do
//Do something
Is ...
2
votes
1
answer
2k
views
Adding variable type declarations and autocompletion in Node / VS Code
I am making a npm library at the moment and was wondering how other people implemented the autocompletion and variable type declarations in VS Code.
For example I can type httpconnection.addListener( ...
0
votes
1
answer
352
views
Bison semantic value of a string, takes everything next to the string also in it
To declare a multiple character variable, I chose to use structure where, there will be a character pointer field and an integer value field. My "testy.l" file has a regular expression for variables ...
2
votes
0
answers
30
views
Declaring multiple variables in one line, what is the order of their creation? [duplicate]
If I declare three variables in one line as below
ClassA a,b,c;
What is the order of their creation?
Is the order defined by C++ standard or it depends on compiler?
1
vote
1
answer
1k
views
JavaScript variable value gets overwritten when checking for "undefined"
I have a function that gets called in two different scenarios.
Scenario 1 gets triggered by a dropbown selection, and I set the variable "sheetName" based on the selected value.
Scenario 2 doesn't ...
0
votes
3
answers
2k
views
Variable declaration inside curly braces
Why does the following code produce an error? I don't understand why the curly braces are making a difference.
#include<stdio.h>
int main(void)
{
{
int a=3;
}
{
...
0
votes
4
answers
104
views
How can I solve this query in sql server?
Sql Fiddle example
I have this table structure:
CREATE TABLE IF NOT EXISTS `client` (
`id` int(6) unsigned NOT NULL,
`name` varchar(200),
`balance` decimal NOT NULL,
PRIMARY KEY (`id`)
) ...
-5
votes
2
answers
80
views
My program doesnt print the result of a function for my last line of code [closed]
This code take input from the user (characters C,T,B) and (int 0-24 and 0-60) to calculate the cost of parking based on the type of vehicle the user inputs.
the last line of code in the program is ...
2
votes
2
answers
3k
views
Is creating arrays with runtime bounds allowed in c++?
According to
C++ : Creating an array with a size entered by the user
creating arrays with runtime bounds is not allowed in c++.
But I get below code compiled without errors.
#include <cmath>
#...