C++ Evaluation
There are three types of variables. Two types deal with numbers only, integers and floats (or real numbers). The other can use any type of character, number or letter. Integer variables, abreviated int, use whole numbers only: int amount; (this is a variable used for integer values only).
Float variables, abreviated float, can use real numbers : float x,y; (these variables will be able to use decimal points)
The last type of variables is characters, abreviated char, and can use both letters and numbers: char return_key; (this is used for a single character)
Printf is the function used for displaying any thing to the use of the program. Typing something into the print function will allow it to be shown on the screen. Varibles can also be displayed, and can be changed by the user if the user enters something into a scanf.
printf("\n Pick a number between 0 and 99."); (this displays the words within the quotation marks onto the screen for the user to see).
Scanf is the function that allows the user to input anything into the program. By entering a question with printf and then using a scan f, the user can input a value for a variable.
scanf ("%i", &account); (this gets the account number from the user, it reads what is within the quotation marks, so it reads one variable, and the variable it reads is stated after).
While loops keep the program repeating as long as the parameters of the while loop are met. Once the parameters are not met, the program will end.
while (option !=4) (this loop will continue running until the option does equal 4, and then it will end).
For loops allow you yo use a multiple varialble set and perform a function with that set, and allow you to use limitations and parameters for the function of that set.
for (int i=1; i<6;i=i+1) (this sets the specific parameters for this set, and says what you want to do with it).
Arrays arejust sets of similar types of varialbes. They allow you to group the variables together in order to do something with the whole set.
int numbers[10]; (this is an array of integers, it contains 10 integers, from 0 to 9).
Functions are just code you can run to perform a certain task. Print and scan are functions, and you can also make your own functions by using variables out side of the main program, and setting operations to them so you can use them with the variables in your main window.
int add(int a, int b) (this is a function to add two integers together, int a and int b. The name of the function is add, and you can use that name later to perform the function).
{
return a+b;
}
If/else statements allow you to set multiple paths to your program. If the requirements of your if statement is fulfilled , you can have one thing happen, and if the requirement is not fulfilled, you can have something else happen. Multiple if statements can also be used with different requirements for each statement, and a different thng can happen for each statement.
if(pins[account]!=entered_pin) (this if/else loop checks to see if a pin number is correct, and if it is it starts another loop).
{
printf("Pin is incorrect\n");
}
else
{
option=0;
while (option !=4)
Comments (0)
You don't have permission to comment on this page.