C++ examples for Language Basics:Console
Use cin to read int value
#include <iostream> using namespace std; #include <iomanip> int main()/*ww w . j a v a2s.c o m*/ { int num1, num2, ans; int her_ans; cout << "*** Math Practice ***\n\n\n"; cout << "What is the first number? "; cin >> num1; cout << "What is the second number? "; cin >> num2; // Compute answer and give her a chance to wait for it. ans = num1 + num2; cout << "\nWhat do you think is the answer? "; cin >> her_ans; // Nothing is done with this. // Prints answer after a blank line. cout << "\n" << num1 << " plus " << num2 << " is " << ans << "\n\nHope you got it right!"; return 0; }