Introduction to C++
Jonah Warrenjonah AT parsons DOT edu
http://www.feedtank.com/2005/cpp
Lab 2
- Create a program that does the following:
- Asks the user for an integer and stores the result in a variable.
- Asks the user for another integer and stores the result in a different variable.
- Print the following information to the screen.
- The result of adding these two numbers.
- The result of subtracting these two numbers.
- The result of multiplying these two numbers.
- The result of dividing these two numbers.
- The result of taking the modulo of these two numbers.
Please enter a number: 10 Please enter another number: 7 The result of adding these numbers is 17. The result of subtracting these numbers is 3. The result of multiplying these numbers is 70. The result of dividing these numbers is 1. The result of taking the modulo of these numbers is 3.
BONUS: Print out the division with a decimal point (but keep the input numbers integers).
- Create a program that uses the following array that represent the ages of 3 people:
int age[3] = {34, 14, 56};Write a program that asks the user to enter a number between 0 and 2. Print out the corresponding age in the array. An example output of your program should look similar to the following:
Please enter a number between 0 and 2: 2 The age of person number 2 is 56.