Exercises


  • Write a program that creates a int, a double, a char, and a bool.
  • Create a program that assigns a value to an int and a double.
  • Write a program to calculate the number of seconds in a year.
  • Your local taco factory just went to the metric system! Convert the current size of your 5 inch tacos to centimeters. Hint: 1 inch = 2.54 Centimeters
  • Write a loop that executes 10 times, each time printing out how many times it has looped.
  • Create an array of 100 integers, setting each to their number in the array (ie, set the 5th element is set to 5, and so on), and then print out each one. Recall that to print out a number, you can say :
        cout << burrito << endl;
    
    Where burrito is a variable inside a program. (More on this next chapter)
  • MegaTaco Inc, makers of the world's best tacos, have decided to replace all of their current 10 ounce tacos with 10.5 tacos. Their current computer system stored the size of their tacos as an int. Think of a way to change the int 10 into 10.5 inside a program.
  • Create a program that multiples an array of 5 integers (try using a for loop) and then multiplies them each by a constant.
  • Modify the above program to print out the array before and after multiplying.


Table of Contents

The Big Picture | Comments | Variables | More on Variables
Variable Operations | Making Choices | More on if | Using else
Using switch | The while Loop | The do..while Loop | Constants
The for Loop | More on the for Loop | Exercises