Here we show how to perform simple input, and some computation.
* This program reads two numbers from the console and prints the total.
// The two input values.
// Request and read input.
std::cout << "Enter an integer: ";
std::cin >> x;
std::cout << "Enter another integer: ";
std::cin >> y;
// Print the total, with proper labels.
std::cout << "The sum of " << x << " and " << y
<< " is " << x + y << "." << std::endl;
New stuff here:
- The declaration of two integer variables will be familiar
- The >> is used to read values.
- Notice that the prompts do not use endl. Lets the
user type right after the prompt.
- Note how the line of ouput is
built from multiple variables and constants.