August 2012
Intermediate to advanced
976 pages
30h 17m
English
In our bookstore problem, we’ll have several records that we’ll want to combine into a single total. As a simpler, related problem, let’s look first at how we might add two numbers. Using the IO library, we can extend our main program to prompt the user to give us two numbers and then print their sum:
#include <iostream>int main(){ std::cout << "Enter two numbers:" << std::endl; int v1 = 0, v2 = 0; std::cin >> v1 >> v2; std::cout << "The sum of " << v1 << " and " << v2 << " is " << v1 + v2 << std::endl; return 0;}
This program starts by printing
Enter two numbers:
on the user’s screen and then waits for input from the user. If the user enters
3 7
followed by a newline, then the program ...
Read now
Unlock full access