|
Welcome to the third chapter ! This chapter is all about getting input from the user of your program. If you haven't done so already, read the first two chapters as they are necessary to understand this one. To get
input we use another C++ object : cin In this chapter I will talk about the basic cin, this will take data from a device ( here your screen ) and store it in a variable. Here's a little example:
MyInt; Say the user typed a '1' , this value would then be stored in MyInt and can be used later with cout cout<<MyInt; This
would input 1 to the screen. Now for a little example program: #include <iostream>using namespace std;int main(){ int MyInt; int MySecondInt;cout<<"Please enter a number"<<endl; cin>>MyInt; cout<<"Please enter another number"<<endl; cin>>MySecondInt; MyInt += MySecondInt; cout<<"number 1 + number 2 = "<<MyInt<<endl; return 0;} Nothing very complicated here, this line may have puzzled you though: MyInt += MySecondInt; This is the same as MyInt = MyInt + MySecondInt; but
faster to write. You can also do -=, *=, /= and %= Thanks for reading
PenTen ( any suggestions, questions or insults :) please send them here )
|