(obvs!) make sure you understand the stated problem
what are the requirements for the program that you're writing?
create supporting materials to help you understand the problem (decision trees, flow charts, etc)
think about how you would approach solving the problem
sketch out how you want your program to work
use pseudocode to get a general idea of your program's flow
design your program
Perfect Squares
print out all of the perfect squares that are less than a number that's inputted by the user
a perfect square is an integer that's the result of squaring another integer
print out the total after all of the squares are printed
if the user enters a negative number, print "negative numbers aren't allowed".
example… user enter 30:
Potential Solutions
For math heavy problems like this, I'll make sure that there's a reasonable brute force (a simple, usually iterative and not necessarily efficient) solution. What are some ways that we can solve this problem? →
we could start counting from 1… and square each number until the square is greater than the input
count up to the number and check if the square root of that number is a whole number (this seems a little trickier)
Let's Write Up a Plan
we can create a flow chart
rectangle with rounded corner - start, stop
rectangles - a generic step in the process
diamonds - a decision point (usually yes or no)
and / or write pseudocode
loose, verbose translation of problem into code
not syntactically correct
A Flow Chart
The utility in this case may be up for debate, but for more complex programs, flow charts are indispensable! Let's try it! →
Pseudocode
Let's also try writing some pseudocode →
Our First Draft
Let's get our first version done. →
Another Version
Our count was wrong, let's fix it. →
Dice Warz!
Let's try a more complicated example. Write a game:
the user and the computer both roll six sided dice
the player that rolls higher gets a point added to their score
First… are these requirements sufficient? What additional questions might you ask? →
is it a graphical game or a text game?
if it's text, how do you roll?
can you leave the game?
etc.
Example Output
Let's flesh out those requirements:
Design Your Program
Write some pseudocode.
Don't Forget the Banner!
We're probably going to have to stop putting code in slides from here on in. I skipped on the banner, and it still didn't fit!