1.2.2
From CppPrimer
Contents |
Exercise 1.3
#include <iostream> int main() { std::cout << "Hello, World!" << std::endl; return 0; }
--Meyvn 14:55, 4 August 2007 (EDT)
Exercise 1.4
#include <iostream> int main() { std::cout << "Enter two numbers:" << std::endl; int v1, v2; std::cin >> v1 >> v2; std::cout << "The product of " << v1 << " and " << v2 << " is " << v1 * v2 << "." << std::endl; return 0; }
--Meyvn 14:55, 4 August 2007 (EDT)
Exercise 1.5
#include <iostream> int main() { std::cout << "Enter two numbers:"; std::cout << std::endl; int v1, v2; std::cin >> v1; std::cin >> v2; std::cout << "The sum of "; std::cout << v1; std::cout << " and "; std::cout << v2; std::cout << " is "; std::cout << v1 + v2; std::cout << "."; std::cout << std::endl; return 0; }
--Meyvn 14:55, 4 August 2007 (EDT)
Exercise 1.6
The code fragment will not compile beyond the first line, since the statement ends there. The following lines try to use the output operator (<<), yet there is no std::cout object defined to write to. Removing the semicolon on the first two lines will allow the program to behave as intended.
--Meyvn 14:55, 4 August 2007 (EDT)
