Jump to content
 Share

Joshy

A Quick Start in Programming

Recommended Posts

Posted  Edited by Joshy - Edit Reason: Added link to next thread

You could become a programmer starting today!

 

I was planning to post this later with better quality, but it looks like this might be helpful now and I can fix it up later. I hope this may encourage some of you to take a stab at it. I'm going to do a lot of hand-waving, and so that you can dig in and start. For the sake of my own time: I'm going to assume you're using Windows although I can update this later to include other OS. Sorry. We'll start with downloading Quincy. It's a very straightforward and small download. My goal at this moment is to have you become familiar with Quincy first so that you may use it for small projects.

 

pXl1gCi.png

 

Let us begin with your first program. No: Not "Hello World." You can find this anywhere else if you really want to (reference). We're going to do a little bit of arithmetic because I believe you will be using this more often if you develop for GFL.

 

LPk9j45.png

 

Choose C++ Source File. This is just to keep things easy although you'll notice my personal style will use mostly C as you learn more. You'll acquire your own style in the future too.

 

YSUtKtn.png

 

Now: You should see a blank text document, which you can type into.

 

VFClmw5.png

 

This is spoon feeding, but copy and paste the following into your text file:

 

#include <stdio.h>

int main()
{

	// Declaration and initial values
	int numX = 0, numY = 0, numZ = 0;
	
	// User interface
	printf("Input first number to add: ");
	scanf("%i", &numX);
	
	printf("Input second number to add: ");
	scanf("%i", &numY);	   
	
	// Operation
	numZ = numX + numY;
		
	// Output
	printf("%i + %i = %i", numX, numY, numZ);
	
	return 0;
	
}

 

It should look like this.

 

RXNFDuH.png

 

Save it as a CPP file.

 

TUORqEF.png

 

9VhprXR.png

 

Now: You have your first program, which I wrote :( I just want you guys to get a feel for it though. Let us run it and see what happens. Click on Debug and then Run. You can also use F9 as a shortcut.

 

OSB37xe.png

 

WbHildF.png

 

Two windows will open upon clicking Yes: A Build window and your program.

 

F7SW2gj.png

 

This is where you'll be able to experience your program as a user, and to debug it should that become necessary.

 

Ny5xsVg.png

 

That was easy! I get that you didn't do anything here besides downloading a file and copying my basic program.

 

No problem! Here's what you can do next:

 

  • Edit my code so that you can perform other mathematical operations such as multiplication or division (using star * or slash /), or make it such that you can add three or four numbers instead of two.

 

Here are some hints:

 

If you need more variables, then you will have to declare them at the beginning of the program. The declarations I used were the following:

 

int numX = 0, numY = 0, numZ = 0;

 

You don't have to "initialize" the values to zero like I did. You can initialize them to other numbers or leave it open although initializing is considered good practice.

 

I used printf() to display something to the user.

 

printf("No hello for you.");

 

You can also have it show variables such as numZ like I did.

 

 printf("My variable, numZ, equals to the following: %i", numZ);

 

What happens if I add 2.5 and 1.2? Will my program still work? My variables are integers meaning they are numbers without those decimal points. You can try other variable types such as a float. You can read more about other variable types here if you would like although I recommend sticking with the basics for now.

 

// Do not forget to declare it!
float numZ = 2.5;
int dog = 3;

printf("numZ wants to be a float like this one %f", numZ);
printf("\nCan dog be an integeter?  I suppose so.  dog = %i", dog);

// That \n makes it on a "new" or "next" line.  This is great for formatting!

 

Scanf() looks suspiciously like a way for the user to type in a value. Don't forget to declare at the beginning if you do use it.

 

float userInput;
scanf("%f", &userInput);

 

Try a few small basic programs and post your results here! If you make an error, then the Builder pop-up window will give you hints as to where the problem is. The most common mistake for new programmers is leaving out the semicolon (;) at the end of the line. Try running the above program with a missing semicolon in one of the lines and see what the error looks like. Make changes in stages instead of doing many changes at once, and so you know exactly what is causing the problem. Good luck!

 

Want to learn more? You can learn follow up with conditions and loops in my next thread:

 

 

Edited by Joshy
Added link to next thread

PoorWDm.png?width=360&height=152

Share this post


Link to post
Share on other sites




×
×
  • Create New...