/*
 *   EE 5C - Programming Assignment #2
 *   Written by Clifford Hwang (clifford@icsl.ucla.edu)
 *
 *   This program will calculate the sum, difference, and product of
 *   two integers.
 */

#include <stdio.h>


/*
 *   get_oneint:
 *
 *      Gets one integer from the user
 *
 *      Parameters: None
 *
 *      Return value: The integer that was read
 */

int get_oneint()
{
   int data;

   printf("Enter an integer: ");
   scanf("%d", &data);
   return(data);
}


/*
 *   calc_sum:
 *
 *      Calculates sum of two integers (n1 + n2)
 *
 *      Parameters:
 *         n1 - 1st integer
 *         n2 - 2nd integer
 *
 *      Return value: The sum of the two integers
 */

int calc_sum(int n1, int n2)
{
   int sum;

   sum = n1 + n2;
   return(sum);
}


/*
 *   calc_diff:
 *
 *      Calculates difference of two integers (n1 - n2)
 *
 *      Parameters:
 *         n1 - 1st integer
 *         n2 - 2nd integer
 *
 *      Return value: The difference of the two integers
 */

int calc_diff(int n1, int n2)
{
   int diff;

   diff = n1 - n2;
   return(diff);
}


/*
 *   calc_prod:
 *
 *      Calculates product of two integers (n1 * n2)
 *
 *      Parameters:
 *         n1 - 1st integer
 *         n2 - 2nd integer
 *
 *      Return value: The product of the two integers
 */

int calc_prod(int n1, int n2)
{
   int prod;

   prod = n1 * n2;
   return(prod);
}


/*
 *   results:
 *
 *      Prints the results of this program to the screen
 *
 *      Parameters:
 *         n1 - integer #1
 *         n2 - integer #2
 *         s - calculated sum
 *         d - calculated difference
 *         p - calculated product
 *
 *      Return value: 1
 */

int results(int n1, int n2, int s, int d, int p)
{
   printf("The sum of %d and %d is: %d\n", n1, n2, s);
   printf("The difference of %d and %d is: %d\n", n1, n2, d);
   printf("The product of %d and %d is: %d\n", n1, n2, p);
   return 1;
}


/*
 *   Main program
 */

main ()
{
   int num1, num2;
   int sum, diff, prod;

   printf("This program will read in two integers and print out\n");
   printf("their sum, difference, and product.\n\n");

   num1 = get_oneint();
   num2 = get_oneint();

   sum = calc_sum(num1, num2);
   diff = calc_diff(num1, num2);
   prod = calc_prod(num1, num2);

   results(num1, num2, sum, diff, prod);
}
