# Problem solving and algorithm design (comp sci)

// C code // This program will provide options for a user to calculate the square // or cube of a positive Integer input by a user.

// Developer: Faculty CMIS102 // Date: Jan 31, XXXX #include // -- the newer C compilers require that functions be prototyped // -- this tells the compiler what the input and output datatypes of the functions are // -- the functions are later defined after the main.

// function prototypes int Square ( int ); int Cube ( int ); int main () { /* variable definition: */ int intValue, menuSelect,Results; intValue = 1; // While a positive number while (intValue > 0) { // Prompt the user for number printf ("Enter a positive Integer\n: "); scanf("%d", &intValue); // test for positive value input if (intValue > 0) { printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: "); scanf("%d", &menuSelect); if (menuSelect == 1) { // Call the Square Function Results = Square(intValue); printf("Square of %d is %d\n",intValue,Results); } else if (menuSelect == 2) { // Call the Cube function Results = Cube(intValue); printf("Cube of %d is %d\n",intValue,Results); } //endif - menuSelect else printf("Invalid menu item, only 1 or 2 is accepted\n"); } } //EndWhile return 0; } /*** Function defintions ***/ /* function returning the Square of a number */ // This function will return the square of the input value // Input: value - input number // Output: return - input number squared (x*x) int Square(int value) { return value*value; } /* function returning the Cube of a number */ // This function will return the cube of the input value // Input: value - input number // Output: return - input number cubed (x*x*x) int Cube(int value) { return value*value*value; }