From dea1f746be7890d2b73612089419034c4c4bc4fd Mon Sep 17 00:00:00 2001 From: cdez Date: Wed, 7 Sep 2022 09:15:14 -0700 Subject: [PATCH] Added the Lab 2 File. --- Lab2/Lab_2_Project.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Lab2/Lab_2_Project.c diff --git a/Lab2/Lab_2_Project.c b/Lab2/Lab_2_Project.c new file mode 100644 index 0000000..8235853 --- /dev/null +++ b/Lab2/Lab_2_Project.c @@ -0,0 +1,57 @@ +// This is lab2 for CS136L +// By Andrew Angus and Charles Descamps + +// include files +#include "Console_IO_Utility.h" +#include "StandardConstants.h" + +//global constants + // this constant is to adjust input to accomodate the 0.45 rounding +const double CHANGE_IN_DECIMAL = 0.55; +const int MULTIPLE_LINE_SPACES = 2; +const int LENGTH_OF_SEPERATOR = 16; + +// main program +int main() + { + + // initialize variables + double valueToRound; + + // prints the intro + printEndline(); + + // need to print the title of the program. + printString("Rounding Program"); + + // prints another blank line + printEndline(); + + // also print a separator (16 equal signs) + printCharacters(LENGTH_OF_SEPERATOR, '='); + + // another blank line + printEndlines(MULTIPLE_LINE_SPACES); + + // Ask user for the value to round + valueToRound = promptForDouble("Enter a value to be rounded: "); + + // Round the value by adding change in decimal, then round + valueToRound += CHANGE_IN_DECIMAL; + valueToRound = (int)valueToRound; + valueToRound = (double)valueToRound; + + // print out the rounded value + printString("The rounded value is now: "); + printDouble(valueToRound, PRECISION); + + // print another blank line + printEndlines(MULTIPLE_LINE_SPACES); + + // Print "Program End" + printString("Program End"); + + // print another new line. + printEndline(); + + } \ No newline at end of file