// Lab 9 - Lownum/Highnum // By Perry Huang /* Write a program which asks the user to enter two numbers into the variables lownum and highnum. The value lownum should be less than the value highnum. If this is not the case, the program should exchange the numbers, placing the low value into lownum and the high value into highnum. Have a function in the program which looks at each number individually and reports back which of the following ranges the number lies in: below 0, from 0 to 50, 51 to 100, 101 to 150, or above 150. Each number should be output along with which variable it is being stored in and what range it lies in. BEWARE: This program uses several of the structures we have been talking about lately. Be sure not to undertreat this problem. */ #include int input(); char* range(int); void main() { int lownum, highnum; char* rangehigh; char* rangelow; puts("This is Lab 9 - Lownum/Highnum program by Perry Huang. Please input two integers and I will display the range the values are in."); lownum = input(); highnum = input(); if (lownum > highnum) { lownum ^= highnum; highnum ^= lownum; lownum ^= highnum; } *rangelow = *range(lownum); *rangehigh = *range(highnum); printf("\n%20s%20s%20s", "Variable", "Value", "Range"); printf("\n%20s%20i%20c", "lownum", lownum, rangelow); printf("\n%20s%20i%20c", "highnum", highnum, rangehigh); } int input() { int integer; puts("Please input an integer: "); scanf("%i", &integer); return integer; } char* range(int num) { if (num < 0) { return("below 0"); } else if (0 <= num <= 50) { return("0 to 50"); } else if (51 <= num <= 100) { return("51 to 100"); } else if (101 <= num <= 150) { return("101 to 150"); } else if (num > 150) { return("above 150"); } }