C++ Programming in Big Bold Red
To Begin All C++ Programs- to begin you must start with the basics to get your code going. there is a generic formation to do so
(at the top)
#include <stdio.h> [stdio stands for standard in/out]
#include <stdlib.h>[stdlib stands for standard library]
*note* there are other <std....>s you can put here but those are the two basics
void main()
{
while(1);
}
Variable Types- Variable types are things that represent another in code
Ex. %i represents intergers [int]
%c represents character [char]
%f represents float
%s represents string [str]
printf- printf is what prints out to the screen
Ex. printf("insert name here: ");
if that is what you would type this is what would show
what you say in the quotation marks ["insert name here:"] will be displayed on the screen.
scanf- scanf is a function that reads data with specified format from a given string stream source. It shows which variables you are going to use in a given sequence.
EX. printf("Insert Number Here: ");
scanf("%i",&c);
when there is a scanf after a printf that means that the variables will be put out on the screen.
if- if statements are used for making decisions
Ex. if (c == r)
{
printf("You Got It!\n");
}
this shows that if your 'c' value is equal to your 'r' value. In this context, if your guess [r] the number [c] in the game then the message of "You Got It!" shows.
else- an 'else' statement is used after an 'if' statement. If it is not the first statement then it is "else" and another thing is printed.
Ex.
if the number is too high then it says so. same with if is too low.
if (c == r)
{
printf("You Got It!\n");
}
else (c > r)
{
printf("Too high!")
}
else (c < r)
{
printf("Too Low!")
}
If the value 'c' is not equal to the value 'r' then if 'c' is greater than 'r' "Too high!" will be printed on the screen. If it is less than "Too Low!'' will be shown.
loops- Loops are used to make something repeat over and over. At the end of an activity (ie a game) it will take you back to the begining.
This simpley shows that after the code is done it then loops to the begining.
arrays- arrays are simply a series of variables or items arranged in a list. you define your array of numbers and then it spits it back out for you.
Ex. array[1] = 1;
array[2] = 2;
array[3] = 3;
array[4] = 4;
array[5] = 5;
array[6] = 6;
This basically shows that you have defined what your array is and that each variable in array is equal to the value you have put in
functions-functions are code you can use to preform a certain task
Ex. printf/scanf
This Is an Example of Code and the program

Comments (0)
You don't have permission to comment on this page.