CS50: How to get a number from a user using GetInt() and Do-While Loop

#include <stdio.h>
#include <cs50.h>

int main (void)
int n;
/* this variable is now declared and available within loop scope */
printf(“Enter a number between 1-23: “);
/* you do not need to declare a variable again instead you can just use it */
n = GetInt();
while (n > 23 || n < 0);
/* if printf is place outside of the while section then the program will just print any number the user inputs instead of only letting them use 1-23 */
printf(“Your number is %d\n”, n);

My Scratch Programming Adventure Explanation

video2 There are three game sections in my ‘Scratch Programming Adventure Game’. The first part is a trivia game and the code template for it can be found in the book ‘Super Scratch Programming Adventure’ which is a book that I highly recommend. It really had a enjoyable time reading it.

video3 The second section code was taken from an online tutorial found at K5 Computer Labs. The original tutorial was called Animal Pong. I finally figured out how to make a timer after reading through quite a few threads about it on the Scratch Discussion Forums. I also made sure that the game would end if you ran out of time on the timer.


The last section of the game is just a simple ‘Guess My Number’ game which I found a template here for on the Scratch Discussion Forums. I had zero luck making the second code example work but the first code example work perfectly and I tweaked it so that if the user guessed wrong that the game would end.



There is a ‘You lose!’ and ‘You win!’ screen at the end of the game with different expressions on the characters faces depending on how you finish the game.




The end screen will either play upbeat music if you win or more downbeat music if you have lost the game.

The Pros and Cons of Learning Scratch Programming

The following text is an excerpt from: Scratch Programming for Teens

As a beginner’s programming language, Scratch teaches you a number of critical programming concepts that you will be able to later rely on should you decide to make the jump to other more traditional and industrial-strength programming languages.

The programming concepts that you can learn from Scratch include:

  • Sequential Processing. This involves the processing of application code blocks, in the order that they are laid out, starting at the beginning of a script file and continuing to the end of the script.
  • Conditional Programming Logic. This involves the conditional execution of code blocks based on data collected during application execution.
  • Use of Variables. This involves the storage, retrieval, and modification of data during application execution.
  • Iterative Processing. This involves the repeated execution of code blocks to process large amounts of information or to control the repeated execution of code blocks required to direct the execution of a game or application.
  • Boolean Logic. This involves the application of programming logic that executes based on the analysis of true/false data provided by Scratch during program execution.
  • Interface Design. This involves the development of user-friendly and intuitive application stage layout, making it easy for users to interact with applications.
  • Program Synchronization. This involves the passage and receipt of messages between application scripts for the purpose of coordinating the execution of different parts of an application.
  • Event Handling. This involves the initiation of script execution based on the occurrence of predefined events, such as the pressing of keyboard keys, the pressing of the green flag key, or the receipt of a synchronization message.
  • Application and Game Development. This involves the creation of different types of computer application projects.
  • Sprite Programming. This involves the use of sprites as the basis for developing graphical programs.
  • Application Troubleshooting. This involves the identification, location, and elimination of programming errors, or bugs, that prevent applications from executing as they are supposed to.

As powerful and fun as Scratch is, there are some programming concepts that it does not teach. These concepts include the storage of collections of data in arrays, the ability to process file input and output, the ability to organize application code into procedures, and the ability to support advanced object-oriented programming techniques. However, as a first-time programmer, these concepts can be challenging to learn, and by omitting them, the developers of Scratch have produced a streamlined yet powerful learning environment, which will prepare you to later make the jump to programming languages that support these advanced programming concepts.