Questions tagged [variables]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
6 views

I'm wondering how to import Django through my Powershell and how to active Django in my PythonPath

I'm trying to import and active Django in my pythonpath, but I still have this message show up in my manage.py tab on VSCode (I'm using Windows 10 and am finding a lot of Linux inputs): ""&...
1
vote
1answer
24 views

Global Variable vs Local variables?

I'm trying to write a function that will be called in main(int argc, string argv[]) for pset 2: plurality. Inside the function, I want a for loop. I've written this: bool vote(string name) { ...
0
votes
1answer
30 views

Problem set 1 Mario variable issue

I've been staring at my computer for so long trying little tweeks to fix the error message. TLDR how do I stop the shadow message from appearing and initialize variable h? The image looks confusing ...
0
votes
1answer
28 views

Substring SQL Search

I am trying to query the Database for a sub-string, I am substituting a string variable from a form for the query. It is giving me a syntax error. This is the error: LINE 1: SELECT * FROM books ...
0
votes
1answer
49 views

How do you make a variable work in multiple loops?

I am trying to solve the vigenere.c problem, but there is one step that I need to figure out before my code works. I am stuck here and I don't know what else I could do. In my code, I have a variable ...
0
votes
1answer
62 views

Declaring a variable in loop or outside

I remember when David talked about declaring variables, he said we couldn't say like 'Hey computer, give me a variable called n' and then later say 'oh hey, give me another variable called n'. The ...
0
votes
1answer
35 views

Pset7 Sell stockprice not a bound parameter

I'm working on sell, and I ran into trouble in one of my db.execute statements. For whatever reason, in the previous line, it was perfectly fine using stock["price"] but in my second db.execute, it ...
0
votes
1answer
31 views

Printing a character times a variable

I have a question about that I would greatly appreciate if someone with knowledge could answer. In C, is it valid to print a character times a variable? For example (spaces and stories are both ...
0
votes
1answer
30 views

Pset2 crack variable changing value for no apparent reason

I'm working on crack and have been messing around with strcmp(), but something isn't working as expected. When I print s (with argv[1] != "hello") it returns the right value, but somehow between the ...
0
votes
1answer
268 views

pset1: cash: How to deal with undeclared variables?

A warning: I know there must be an easier way to make this script work. But I'm a newb who has a very hard time wrapping my head around programming and I don't want to destroy my thinking by looking ...
0
votes
1answer
64 views

Hello, I have a problem with the water consumption code in pset 1

I have a problem with the water consumption code in pset 1. #include <cs50.h> #include <stdio.h> int main(void) { printf("Minutes:"); int n = get_int(); } An error ...
0
votes
1answer
247 views

Pset4 Recover not working

I am working on pset4's recover. My variable, outptr, is not being recognized by other parts of my do-while loop. Why is this? #include <stdio.h> #include <stdlib.h> #include "...
0
votes
1answer
37 views

scope of local variables

If I run following code, I get output From inside innermost braces c is 5 from just outside innermost brace, c is 8 from inside function 48 From just before end of main c is 8 But if I change ...
1
vote
2answers
36 views

C: Pset 3: Binary Search - 'expected an exit code of 0, not 1' (not finding n)

This is an attempt at binary search. n is the user input (from main script). This code compiles but doesn't find the needle in the haystack. I'm a bit lost and would welcome assistance. bool ...
0
votes
2answers
22 views

Error when assigning a structure to another of the same type

It seems like the following should copy t1 into t3 (that seems to be what the documentation I have read suggests) #include<stdio.h> struct test { int a; char* name; struct test* b; }; ...
0
votes
1answer
67 views

What does “using” a variable entail and why does this inconsistency come up? (pset1, greedy, general question)

During the greedy problem in pset1 I wrote this function: void greedy(int coin_type, int *change, int *coins) { while (*change / coin_type > 0) { *coins++; *change -= coin_type;...
0
votes
1answer
39 views

Problem with pointers, getting seg fault while indexing with variable instead of plain number

I would like to ask why is that giving me seg fault. int **a = (int**) malloc (sizeof(int*) * 3); a[0][0] = 1; a[0][1] = 2; a[0][2] = 3; for(int i = 0; i < 3; i++) { printf("%d",...
0
votes
1answer
40 views

Multiplication function error?

I'm getting an error for the value of c when I test this code... when I input '2.10' as the x value, c= x*100 gives me a value of 209?? For other values it seems to work so far, weird. I'm new to ...
0
votes
2answers
325 views

global variables and macros

if we use #define a 1 - MACROS or int a = 1 - Global variables before main function what is the difference between the both of them assuming I won't alter the value of global ...
0
votes
1answer
21 views

calculations vs variables performance

In recursive scenarios, what brings more performance? Doing 3-4 simple calculations once, store result on a variable and then use variable maximum 3-4 times in each recursive function call? Or to skip ...
0
votes
1answer
303 views

Use of functions and variable declarations outside main() on pset1 greedy

I have completed greedy from pset1 and I still doubts about the variable declarations and the function position. What is the difference if they are declared inside or outside the main function? #...
0
votes
2answers
181 views

pset1 mario Initializing for loop from GetInt

I'm running the Mario program and I have everything working except the correct count, which I can fix. The only issue I'm having is a syntactical one. I'm tying to initialize the "for loop" with the ...
0
votes
2answers
101 views

Whats's difference between declaring and defining variables?

According to lectures all variables we use are declared as int x = something; or int x; But in pset3..in files that Cs50 staff made,they have done; #define DIM_MIN 3 and #define DIM_MAX 9 So ...
0
votes
1answer
130 views

Can I create an element of arbitrary size in a STRUCT?

I'm working on recover.c. It seems like a tidy solution to eliminate fseek calls would be to create a struct like the following: typedef struct { BYTE first; BYTE second; BYTE third; ...
0
votes
1answer
429 views

Difference between Pass by Value and Pass by Reference (a practical example)

at the end of Doug's video on arrays he explains how variables get passed in function calls in comparison to how arrays work. void set_array(int array[4]); void set_int(int x); int main (void) { ...
0
votes
1answer
852 views

How can I pass an array or a long long unsigned variable as an argument to a function?

Okay, I admit I have no business doing the "hacker edition" problems, but I am having so much fun with this that I want to do ALL THE PROBLEMS! Anyway. I'm working on pset1 hacker edition "credit." ...
0
votes
0answers
23 views

Issue Initializing variable

I hope someone can help clear this up for me. If I use this I get an error: int i = GetInt(); https://gist.github.com/anonymous/7707d2b851d40106c525#file-gistfile1-txt I get an error... but if I ...
0
votes
1answer
24 views

How do I use my own function for ball movement and call it in main, rather than writing it in main

I've successfully written code inside the while loop in main that makes the ball bounce correctly. However, first I tried to call a function from main (just to make it easier to read), called ...
1
vote
1answer
372 views

Pset2 caesar unused variable

Hello and thanks for reading. I have created a few functions and at the moment I have no idea if my code works, so I just want to test to see if my code works but I am getting a weird error which I'...
0
votes
1answer
54 views

Error Message while doing Greedy for declared variable

greedy.c:8:7: note: previous definition is here int i; This variable has been declared and used and I am getting this error message. If I remove the declared variable then it tells me I didn't ...
0
votes
1answer
263 views

compilation error multi-character character constant in caesar

The code is: string plaintext = GetString(); for (int i = 0, n = strlen(plaintext); i < n; i++) { printf("%c", plaintext[i]); if ((isalpha(plaintext[i])) && (isupper(...
5
votes
3answers
223 views

what happens to memory when a variable dies?

Whenever a variable dies, the memory is erased. But is the content of the memory erased? And if so what happens to the contents of the memory ? Why do we see garbage values (that many times does not ...
0
votes
1answer
342 views

Get more than one inputs in same line without pressing enter key

I want to make a calculater that takes input like 23 + 24 The two ints or floats plus the character in the same line Tried float a = Getfloat(); char c = GetChar(); float b = Getfloat(); With this ...
0
votes
2answers
148 views

Error using string as a data type while including the cs50 library

I am receiving the following error while compiling my code: jharvard@appliance (~/Dropbox/pset2): make initials clang -ggdb3 -O0 -std=c99 -Wall -Werror initials.c -lcs50 -lm -o initials initials....
1
vote
1answer
43 views

Why does this check for equality fail to trigger in my Scratch project?

I attempted to make a basic game where you should click the Dragon and not the girl. I wanted to make it so that when you click the girl you lose a health point and when your health point reaches 0 ...
2
votes
1answer
13k views

How to initialize multiple types of variables in a FOR loop?

Is there a way to initialize two different types of variables in a for loop? For example: for (int i = 0, n = strlen(oldStr), char a, b; i < n; i++) So the variables i and n are ints while a and ...
1
vote
1answer
128 views

Global Variables vs #defined Constants

Every time they talk about global variables, it's generally considered "bad practice" to use them unless there is a compelling reason to. #defined CONSTANTS on the other hand, seem to be fair game. ...
0
votes
2answers
75 views

Multiple byte storage and comparison

How should I by using these bytes(spaces in between each bytes?) and What type of variable would nf need to be in this context? if(nf == 0xff 0xd8 0xff 0xe0 || nf == 0xff 0xd8 0xff 0xe1)
0
votes
1answer
72 views

How on Earth can this variable change without any commands? Please help!

As you can see, the value of buffer[0] changes when the line sprintf(tittle, %03d.jpg", images);, which has nothing to do with the buffer. All of the values in buffer are changed. I went through my ...
3
votes
2answers
2k views

How to Declare and Initialize Variables in C?

While I was watching the walkthrough for pset2 (capitalize), I noticed that David didn't declare a variable in his program. However, it still worked and I was wondering why. I tried to implement my ...