Questions tagged [scope]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
1answer
43 views

CS50 Credit - again a scope problem

I think I almost finished the credit problem set, however, I have another scope problem. I think it is really simple. After the checksum, the code is not working anymore. If I put extra braces by the ...
0
votes
1answer
19 views

Scope problem - not print the test results

I have trouble with my scope (PS1, credit) I am using two while loops and to test the result, i print results in between. This code does not print the second printf. I think it is a scope problem but ...
0
votes
1answer
61 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
34 views

do while mistake , please give right code

#include <cs50.h> #include <stdio.h> int main(void) { do { int n=get_int("positive no:"); } while(n<=0); for( int i=0;i<n;i++) { printf("#\...
0
votes
1answer
61 views

Initials: Not printing second initial

I'm having some trouble getting started with the initials problem. Currently, if the user inputs: John Smith, only J is printed. I'm assuming the program automatically exits after the first print ...
0
votes
1answer
30 views

Why do I have to declare variables outside of my main function for them to be picked up? (Scope)

If I place my arrays outside of the main function as global variables, my Merge-Sort works. If i declare unsortedArray or tempArray or BOTH inside of the main function, the terminal lights up with ...
0
votes
2answers
2k views

Can I declare a variable *within* a do-while loop?

As you can see in the following code, I declared my height variable before the do-while loop (on Line 5). Would it have been better -- or even possible -- to perform this step within the loop? In ...
0
votes
1answer
240 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
23 views

where to initialize the variable that keeps track of the blank space

I am working on "Move" of exercise Fifteen in PSET3 of CS50. I am unsure about how to keep track of the blank space. I have tried to add the row and column number of the initial blank space as a ...
0
votes
1answer
57 views

pset3 binary search code is not compiling

this is my code for binary search. bool binary(int key, int array[], int min, int max); bool search(int value, int values[], int n) { if( n< 0) { return false; } ...
0
votes
1answer
83 views

PSET 4, recover: Have a problem with scope I think

Going crazy here, help much appreciated:). I think I am messing something up with the scope. Here is my analysis for what it's worth: I am declaring img within the if & else conditions. Because of ...
0
votes
2answers
93 views

Pset3 Breakout: Question on variable scope in while loop

I'm working through pset3 and noticed that when I declare my ball's velocities outside the while loop, my collisions against the wall's edges work, i.e. the ball bounces away, but when the velocities ...
0
votes
1answer
305 views

using root and current nodes in check when not declared until load

So i have used a trie structure for this pset. And i have declared my struct node in the load section as well as root and current which are nodes. I've written my code for check but I need to access ...