The First Program
Simple input and output are the focus of this this tutorial. It should also serve to make you feel comfortable with the compiler in your development environment or how to use your shell.
Tasks
Write a single program for each of the following:
- L0: The all time classic: Write a program that prints "hello world" on the screen.
- L0: Enter a number and print it on the screen.
- L1: Enter a string and print it on the screen.
- L1: Enter two numbers and print the sum of these two values.
- L1: Enter two numbers and print the result of the operation
on the screen. Remember to keep the valid values for
in mind!
If you do not know the meaning of the red L's have a look at this link.
Issues
Always check the pre- and postcondition for each algorithm. Implement checks for errors as required.
C++ Reference Implementation
#include<iostream> int main() { double a, b; std::cout << "Please enter a: " ; std::cin >> a; std::cout << "Please enter b: " ; std::cin >> b; if (b !=0.0) std::cout << "Result of a/b: " << a / b << std::endl; return 0; }