Presentation is loading. Please wait.

Presentation is loading. Please wait.

Objective: Students will be able to: Declare and use variables Input integers.

Similar presentations


Presentation on theme: "Objective: Students will be able to: Declare and use variables Input integers."— Presentation transcript:

1 Objective: Students will be able to: Declare and use variables Input integers

2 Variables Hold data Can be numbers, letters, words Place in main memory that holds the data Has a name that is assigned by the programmer

3 Example int alice; Type: int integer (whole number) alice: name of variable Variable is declared. ;

4 program to input an integer and have it print out (echo) #include using namespace std; int main (void) { int alice; cin >>alice; cout<< “There is an echo “; cout << alice; cin.get(); return0; }

5 Variable Names Can consist of numbers, letters, and underlines Can be as long as you like Provided that: It starts with a letter It is unique for that program somewhere in the first 32 characters Doug and doug are different Can’t be a keyword

6 Examples of variable names count Sum Salary, Next_character total reply

7 Type in and run the cin program. Make sure to type a number in when you run the program What were the results:

8 Assignment One way to assign a value to a variable is to input a number from the keyboard like we just did in the last program. Another way is to use an assignment statement: int alice, bill;declares variables cin>>aliceinput number for alice bill = alice;makes bill equal to alice cout<< bill;prints out number inputted

9 Self Test: What do these lines of code do? int Alice, Tom; cin >> Alice >> Tom; Alice = Tom; Tom = Alice; cout << Alice << Tom;

10 Answer goes here!

11 Self Test: What do these lines of code do? int Alice, Tom, Save; cin >> Alice >>Tom; Save = Alice; Alice = Tom; Tom = Save: cout<< Alice << Tom;

12 Answer goes here!


Download ppt "Objective: Students will be able to: Declare and use variables Input integers."

Similar presentations


Ads by Google