Presentation is loading. Please wait.

Presentation is loading. Please wait.

Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – 2.5-2.8 Lab 1 – due Monday.

Similar presentations


Presentation on theme: "Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – 2.5-2.8 Lab 1 – due Monday."— Presentation transcript:

1 Declarations/Data Types/Statements

2 Assignments Due – Homework 1 Reading – Chapter 2 – 2.5-2.8 Lab 1 – due Monday

3 Example Declarations double mynum; int count1, count2; char initial; Syntax type name;

4 Data Types int –integer value –10, 0, -23 float –floating point number –1.5, 34.3565 double –decimal number –store more digits than floats char –character –‘A’, ‘d’, ‘]’

5 Declarations #include void main (void) { int x; statements; } 0 1 2 3 4 x: Allocate enough space for the given type and associate a name with the space

6 Assignment Statements tax = cost * TAX_RATE; Perform calculation on right and store in variable on left Also legal: total = total + cost;

7 Input and Output printf("Enter cost of item: "); scanf("%lf", &cost); printf("The tax on your item is $%5.2lf.\n", tax); printf("The total cost of your purchase is $%5.2lf.\n", total);

8 printf (“Format string”, printlist); Placeholder –starts with % –%c – char –%d – int –%f – double –%lf – double Precision printf("Enter cost of item: "); printf("The tax on your item is $%5.2lf.\n", tax);

9 printf \n – go to a new line printf (“Calculate %d plus %d.”, num1, num2); printf (“Hi %c%c!”, first_initial, last_initial);

10 scanf Read in data of the specified type and store it in the specified box & -- specifies the box, not the value cost -> 1234.56 &cost -> 1024 scanf("%lf", &cost); cost: 1024 1234.56

11 scanf scanf(“%d%d”, &num1, &num2); scanf(“%c%c”, &first_init, &last_init); careful with this, even return is a character!


Download ppt "Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – 2.5-2.8 Lab 1 – due Monday."

Similar presentations


Ads by Google