#include<iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
//program goes here
return 0; //ends program
}
to output a line, use cout with the "stream insertion" operatror:
cout << "this is the line I am outputting. ";
to get user input, use cin and the "stream extraction" operator:
int yourVariable;
cin >> yourVariable; //loads input into yourVariable
Of note is that cout can output a wide variety of "cascaded" variables one at a time like this:
cout << "This: " << yourVariable << " is your variable." << endl;
//where endl dumps text onto the screen (unloads buffer)
// and starts on a new line
If "yourVariable" is, say, 4, the above line will output:
This: 4 is your variable.
So anyway, to relate this all to your question, use cout to ask for integers, cin to load them into variables, assign the sum of the numbers to a variable:
variable3 = variable1 + variable2; //there are other, more
//complicated ways to do this.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.