Lab 5 - Midterm 1 solutions and printf

The midterm 1 solution guide is posted in the Solutions section (opens a new window).

The printf() function is the C-style method of printing output to the screen. It can take multiple arguments. The first argument is always a format string. The format string can be either just a plain string (in which case it is the only argument to printf) or a string with formatting tokens embedded in it. The tokens dictate how to display certain datatypes. It takes the form: %[col][.prec]type. The type is d for an integer, f for a double and c for a character. The column width and precision are optional.

Examples:

Take the following program and input it into a file on Helios. Compile and run it.
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int num1, num2;
  double dnum1, dnum2;

  printf("Enter two integers: ");
  cin >> num1 >> num2;
  print("Enter two doubles: ");
  cin >> dnum1 >> dnum2;

  print("%d %d %f %f.\n", num1, num2, dnum1, dnum2);
  print("%10d %10d %10f %10f.\n", num1, num2, dnum1, dnum2);
  print("%10d %10d %10.2f %10.3f.\n", num1, num2, dnum1, dnum2);

  return 0;
}
Now alter that file and try the following formatting changes: Email me your final version of the above program after playing around with the formatting changes.