All pastes #754640 Raw Edit

perry753

public c v1 · immutable
#754640 ·published 2007-10-30 03:56 UTC
rendered paste body
// Lab 9 - Lownum/Highnum// By Perry Huang/*Write a program which asks the user to enter two numbers intothe variables lownum and highnum. The value lownum should be lessthan the value highnum. If this is not the case, the program shouldexchange the numbers, placing the low value into lownum and thehigh value into highnum. Have a function in the program which looksat each number individually and reports back which of the followingranges the number lies in: below 0, from 0 to 50, 51 to 100, 101 to 150,orabove 150. Each number should be output along with which variable itis being stored in and what range it lies in.BEWARE: This program uses several of the structures we have beentalking about lately. Be sure not to undertreat this problem.*/#include <stdio.h>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");	 	}}