Numeric Input

A program that performs calculations on predefined numbers is a good start, but most programs need to perform operations on data from the outside world. So let's extend the example again as shown in Listing 4.1.

Listing 4.1. Getting Numeric Input from the User
 1: #include <iostream> 2: 3: using namespace std; 4: 5: int main(int argc, char* argv[]) 6: { *7: int Dividend = 1; *8: cout << "Dividend: "; *9: cin >> Dividend; *10: *11: int Divisor = 1; *12: cout << "Divisor: "; *13: cin >> Divisor; 14: 15: int Result = (Dividend/Divisor); 16: cout << Result << endl; 17: 18: // Note: You must type something before the Enter key 19: char StopCharacter; *20: cout << endl << "Press a key and \"Enter\": "; *21: cin >> StopCharacter; 22: ...

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.