iasteele

 

Harika

Page history last edited by Anonymous 2 yrs ago

 C ++ Enrichment

 

 

1. Variables- Have to be defined before you use it so the computer can recognize it.

  • char(character) - any number, letter or symbol
  • int(integer) - any whole number
  • float- real number
     

 

2. Printf Function

  • Outputs information to the screen.
  • Ex) printf("Pick two numbers\n");

    - Enclosed in Parentheses and Quotation Marks. \n means skip a line. Always end with semi-colon.

     

     

     

 3. Scanf Function

  • Gets information from the user and puts it on the screen.
  • Ex) scanf("%i %i", &a, &b);

    -%i means integer and & is required before variables for all scanfs.

    -Enclosed also in parentheses and ends with a semi-colon.

     

     

 4. If/else

  • They are the backbone of programming and make everything else possible. They are used for making decisions.
  • They say if something, do this. If else do this. And let you react to different situations.
  • Ex)

    if

    {

    printf("correct! Your current score is %i!\n",score);

    }

     

    ( guess == r )else

    {

    printf("wrong, your current score is %i.\n",score);

    }

     

    {

    printf("too low\n");

    }

     

    {

    printf("too high\n");

    }

    - Enclosed in curly brackets and use printf functions. Use the words if and else.

    if( gu
    ess < r)if( guess > r)

 

 

 

 

Loops (ex. while and for):

  • Codes used to make a certain action repeat again and again.
  • If you were creating a game, you could use a loop to allow the user to play the game continuously until they win.

 

Arrays:

  • The number of variables of a certain type.
  • Arrays are used as parameters to certain variables that define the quantity of the certain variable.

 

Functions:

  • A code that is already working and is refered to by a single command
  • ex. printf.
  • Functions are precreated and can be used to carry out complex task with just a single command.

 

 

 

 

 

 

Comments (0)

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