![]() |
|||||||||||||||
|
|||||||||||||||
|
Chapter 4 - InputNow we know how to construct programs that can do at least the basic algorithical functions (+, -, * and /), but each of these programs require the programmer to create a new program and compile it for every single new task. Even a program that will only add together two numbers must be recreated if we only want to change one of the numbers. That's why we need user input. Now imagine this simple addition program. What if it could ask the user for two numbers and then add them together and print the result. Easy enough. What we need is another function in iostream.h called cin who is the, you guessed it, sibbling of cout. cin works pretty much in the same way as cout but the streaming goes in the other direction, like so: #include <iostream.h> This should be easy enough to understand. We create two integer variables (Var1 and Var2), ask through cout for values to assign to them (which we catch from the keyboard with cin). These values are then added together during the cout streaming. < Previous Chapter | Next Chapter > |
Johan Thorstensson, 2003©