08 Fundamental Data types

08 Fundamental Data - z and then uses it when the user enters it int z cin>> z Two inputs int z int a cin>>z>>a-Multiple inputs are

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Fundamental Data Types Numbers: Integers (int): cannot have a decimal point & double: a floating point number (can have a decimal point) -integers are used to make your intensions clear (eg a certain number should not have a decimal) and because an integer takes up less space and memory. Declare and assign: int a; (declare) a=3; (assign) int a=3; (initialize) Variable Names: -1st character has to be a letter or an underscore -following must be letters, numbers, or underscore -all are case sensitive Convention: -Variable names start with lower case -use underscore or camel case foe multiple words example: interest_rate or interestRate (camel case) Cin and Cout: Cout is used to put words on the screen exactly as typed or to put out a variable cout<<"write this on the screen"; cout<<interest_rate; cout<<"The interest rate is " <<interest_rate <<"\n"; Cin is used to take input from the user. In the example it asked the user for the value of
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: z and then uses it when the user enters it. int z; cin>> z; Two inputs: int z; int a; cin>>z>>a;-Multiple inputs are seperated by white space (space, tab, or return) Comments: Used to keep track of what you are doing when codes begin to get longer. When using comments you can write comments in the code that the compiler will ignore. \\ (will ignore this line) /* (will ignore everything between the two slashes and stars) *\ Mathematical Stuff: addition, subtraction, and multiplication Depending on whether or not you use a double or an int it will just add(+) subtract(-) and multiply(*) when you tell it to double total = 0.01 + 0.24; cout<<"Total =" << total << "\n"; This would display: Total=.25 Devision: Inter division: 7/4=1 % will give you the remainder of integer division 7%4=3 Floating Point division: 7.0/4=1.75 (one of the numbers has to be a double)...
View Full Document

This note was uploaded on 05/19/2008 for the course PIC 10A taught by Professor Wittman during the Spring '08 term at UCLA.

Page1 / 2

08 Fundamental Data - z and then uses it when the user enters it int z cin>> z Two inputs int z int a cin>>z>>a-Multiple inputs are

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online