A-level Computing/AQA/Paper 1/Fundamentals of programming/Data types

Most programming languages have built in data types that are used when declaring variables. Some common data types, and the ones you need to know for the exam, are as follows: Using these data types we can start to write a simple computer program:

But wait a second, this gives you an odd output, it says:

hello Barry! you are 56 years old

I told it that Barry was 56.3 years old! The reason is because I have used an integer to store the age and not a real (single or double) datatype, it therefore drops the decimal part. Integers, afterall, don't store decimal places!

Assignments
Depending on the datatype, we assign values in different ways:
 * Integers, Bytes, Real, Singles, Doubles = Plain assignment without speech marks


 * Boolean = Plain assignment without speech marks


 * String, Char = Assignment with speech marks


 * Date = Assignment with speech marks

Using the correct datatype declare variables for a person's:
 * Age
 * Name
 * Gender
 * Height (metres)
 * Date of Birth
 * License (Do they have a driving license?)

Write assignment statements for the following variables using yourself as an example:
 * Name
 * Age
 * Gender

Which of the following declarations are correct, which are wrong and why?

Which of the following assignments are correct, which are wrong and why:

Give two reasons why is it important to get the correct datatypes:


 * Prevents mistakes in code and calculations at run time
 * Makes for smaller and faster programs

Write code that asks the user to insert three numbers with decimals, then outputs them (1) all multiplied together, and (2) added together. For example:

Please insert number 1: 2 Please insert number 2: 3 Please insert number 3: 7.8 multiplied together = 46.8 added together = 12.8

You don't need to know this part for the exam, but it should help you understand why we need to convert. We have two types of programming language: strongly typed and weakly typed. Strong typing means that you can't add a string to a integer, even if the string contains a number. Weakly typed languages allow you to add a string to an integer if the string contains a number.