/* File: CleanFunctionExample.c
By: Christopher Manloloyo
*/
/* This Program is a function variation of Variables.c */
#include<stdio.h>
float print_then_add(int x, float y);
int main()
{
// declare variables
int i_am_an_integer;
char i_am_a_char;
float i_am_a_float;
double i_am_a_double;
float sum;
// initialize variables
i_am_an_integer = 11;
i_am_a_char = 'c';
i_am_a_float = 1.23;
i_am_a_double = 1.23;
// use variables
printf("This is an integer: %i \n", i_am_an_integer);
printf("This is an char: %c \n", i_am_a_char);
printf("This is an float: %2.3f \n", i_am_a_float);
printf("This is an double: %f \n", i_am_a_double);
//Function Call
sum = print_then_add(i_am_an_integer, i_am_a_float);
/*
sum = print_then_add(i_am_an_integer, (float)i_am_an_integer + print_then_add((int)i_am_a_float, i_am_a_float));
*/
printf("The sum of the integer and float is: %3.5f \n", sum);
}
float print_then_add(int x, float y)
{
//float sumOfNum;
// print the values for x and y
printf("The value of x in the function is : %i \n", x);
printf("The value of y in the function is : %f\n", y);
// Return The Sum
return (x+y);
// Alternatively, we could write the code in comments below.
//sumOfNum = x+y;
//return sumOfNum;
}