iasteele

 

Aiman

Page history last edited by Aiman 2 yrs ago

 

 

Beginnings

 

The Basics of C++ are quite simple

 

whenever you start a code you want to include the library resources so that the prject works properly

    #include <stdio.h>

    #include <stdlib.h>

 

    void main()

    {

 

 

 

 

    }

 

After inputting this base you are ready to start your coding, the code will begin between the two curly brackets { }

 

The Basics

    There are a few basic types of codes we learned.

  • Variable Types
  • printf
  • scanf
  • if/else
  • loops (while and for)
  • Arrays
  • Functions

 

Variable Types

    Some of the variable types used were integers, characters and float.

Integers are any whole number positive or negative as long as they don't have a decimal value. They are represented by %i

Characters are Words or letters such as when you enter a name into the program. They are represented with %c

Float is the number of Signifigant figures. This is represented with %f

 

printf

    printf is one of the most basic and essential codes for C++ programming it tells the program what information to display to the user without it most people would be lost.

                                              scanf("Text")

 

 

scanf

    scanf is almost like the opposite of printf instead of the program deciding what information to give to the user, the user is inputting information to the program.

                                              scanf("What to do with Given Info")

 

if/else

    This function basically tell the program that after whatever happens depending on the outcome it will do something like in the pick a number game we made.  if the right number was picked something happened as opposed to what happened if you didn't

                                              if(condition)

                                                    Else(other consequence)

 

Loops

    Loops determine the running of the program without a loop code in the program sometimes the program will close even before you see it.  Sometimes this is used to repeat actions in combination with the if/else

                                              while(1)

 

Arrays

    Arrays are used to calculate values of numbers without using specific operations

                                              for ( int i = 0; i <= 9 ; i = i + 1 )

 

Functions

    Functions are operations in which someplace variables are placed and the calculations are done somewhere else and then returned to where they are needed.

 

Another Way to say it is just predeterming operations so you can easily reference them later in the code.

 

                                              int subtract(int a, int b)

                                                {

                                                return a-b;

                                                }

 

 

 

 

 

Comments (0)

You don't have permission to comment on this page.