Docsity

CONDITIONAL STATEMENTS IN C, Exams of Computer Science

Toggle sidebar
bg1
CONDITIONAL STATEMENTS IN C
Variables - <<<<<CORRECT ANSWER>>>>>Containers for storing data values
Data stored can change throughout a program (e.g. score can go up and down)
To assign a variable you use an = sign
Example: name = Bob
Variables - <<<<<CORRECT ANSWER>>>>>String
- Text
- One letter, one word, series of words
- strName = "Bob"
Integer
- Numeric
- Whole number
- intAge = 15
DATA TYPES
- Float
- Numeric
- Decimal
- fltTemperature = 20.5
Boolean
- Two options
- boolMember = True
Control Structures - <<<<<CORRECT ANSWER>>>>>Sequence
- a list of instructions
- followed in order (like a recipe)
Selection
- allows the user to make a choice from options
- use IF, ELIF and ELSE
Loop/ Iteration
- used so we don't repeat code over and over
- allows for a section of code to run multiple times
- use WHILE or FOR
Operators - <<<<<CORRECT ANSWER>>>>>Arithmetic operators
used to perform mathematical equations
Addition +
pf3
pf4

Partial preview of the text

Download CONDITIONAL STATEMENTS IN C and more Exams Computer Science in PDF only on Docsity!

CONDITIONAL STATEMENTS IN C

Variables - <<<<< CORRECT ANSWER >>>>>Containers for storing data values Data stored can change throughout a program (e.g. score can go up and down) To assign a variable you use an = sign Example: name = Bob Variables - <<<<< CORRECT ANSWER >>>>>String

  • Text
  • One letter, one word, series of words
  • strName = "Bob" Integer
  • Numeric
  • Whole number
  • intAge = 15 DATA TYPES
  • Float
  • Numeric
  • Decimal
  • fltTemperature = 20. Boolean
  • Two options
  • boolMember = True Control Structures - <<<<< CORRECT ANSWER >>>>>Sequence
  • a list of instructions
  • followed in order (like a recipe) Selection
  • allows the user to make a choice from options
  • use IF, ELIF and ELSE Loop/ Iteration
  • used so we don't repeat code over and over
  • allows for a section of code to run multiple times
  • use WHILE or FOR Operators - <<<<< CORRECT ANSWER >>>>>Arithmetic operators used to perform mathematical equations Addition +

Subtraction - Multiplication * Division / Assignment operators used to assign values to variables Assign = Add to += Minus from - = Example

  • score += 1 Comparison operators used to compare two values Equal to == Not equal to != Greater than > Less than < Greater than or equal to >= Less than or equal to <= Example if score == 0 while time > 20 Pseudocode - <<<<< CORRECT ANSWER >>>>>Describes the steps in a solution by using words Not specific to any one programming language Written in plain English, but follows different conventions Used as a plan for a solution (program) Indentation is very important Console - <<<<< CORRECT ANSWER >>>>>A text-based program interacts with the user using text only (typing commands) Input is entered via the keyboard, and output is displayed as text Advantages:
  • Simple and fast to develop Disadvantages:
  • Less visually engaging GUI (Graphical User Interface) - <<<<< CORRECT ANSWER >>>>>A GUI program allows users to interact using visual elements (buttons, icons, text boxes etc.). Interaction is typically through a mouse, touch, or keyboard. Advantages:

Common Errors - <<<<< CORRECT ANSWER >>>>>Syntax error - Mistakes in code structure (e.g. missing "" or : ) Runtime error - Program crashes while running. Logical Errors - Program runs but gives wrong output (e.g. program did not do what you wanted it to do)