Professional Documents
Culture Documents
02 - Variables and Data Types
02 - Variables and Data Types
04/05/24
Chapter Overview
2
2. Data types
3. Arithmetic operators
4. Input statement
5. Operator precedence
04/05/24
Variables
3
totalSales Yes
total_Sales Yes
Examples
distance = rate * time;
count = count + 2;
5 is an integer literal
04/05/24
Things to consider while using numeric data
12
Some integer
variable definitions:
- On separate lines:
int length;
int width;
unsigned int area;
04/05/24
Input Example using cin
#include<iostream> 25 OUTPUT
void main( ) {
Enter value for i = 7 8 6
clrscr(); value of i = 65000
int i; float j; char w; Enter value for j = 5.8 9
value of j = 100000
cout<<“Enter value for i = ”; Enter value for w = c
cin>>i;
value of k = 543.77
cout<<endl<<“Enter value for j = ”; The value
valueyou
of lentered
= for i = 786
50000.897
cin>>j;
cout<<endl<<“Enter value for w = ”;
value
The value you m =90000.8997
of entered for j = 5.89
cin>>w; value
The value of entered
you c =w for w = c
cout<<endl<<“The value you entered \
for i = “<<i<<endl<<“the value you \
entered for j = “<<j<<endl<<“the value\ you entered for w = j i
“<<w;
}
04/05/24
Precedence
30
1. Problem Solving with C++ (10th Edition), Walter Savitch, Addison Wesley,
2018
2. CS201 Introduction to Programming, Virtual University of Pakistan
3. Paul J. Dietel, C++ How to Program (10th Edition), Pearson, 2017.
4. Turbo C programming for the PC, Robert Lafore
04/05/24