All pastes #538966 Raw Edit

LordBoBCUP

public c v1 · immutable
·published 2007-06-05 04:33 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>	void division(int x, int y, int z[], int count);    int main() {    char strInputDividend[15], strInputDivider[15], strInputFloatingPoint[15]; /* arrays of characters read in from the keyboard and validated against the requirements for the input.*/    int c; /*this is the character being read of the keyboard */    int loop, error, temp2; /* temp, temp1, temp2 are just variables used to hold the result of functions. error is used to test if there is an error in the input. loop is used in forloops */    int intInputDividend, intInputDivider;    int floatingPointArray[15];    error = 0;/*---------------------------------------------- * * This loop and the following loops are the input and validation of the input gained from the user. * Basic tests are done on the data to see it is integers being passed, and also the messages are printed to the terminal. * *---------------------------------------------- */	while (error != 1){		error = 0;		printf("Dividend?\n");		for (loop = 0; (c = getchar()) != EOF && c != '\n' && loop < 15; loop++){			if (c >= '0' && c <= '9'){				strInputDividend[loop] = c;			}			else			{				error = 1;			}		}		if (error == 1){			printf("Wrong Entry\n");			error = 0;		} else {			break;		}	}	while (error != 1){		error = 0;		printf("Divider?\n");		for (loop = 0; (c = getchar()) != EOF && c != '\n' && loop < 15; loop++){			if (c >= '0' && c <= '9'){				strInputDivider[loop] = c;			}			else			{				error = 1;			}		}		if (error == 1 || strInputDivider[0] == '0'){			printf("Wrong Entry\n");			error = 0;		} else {			break;		}	}	while (error != 1){		error = 0;		printf("Number of doubleing digits required?\n");		for (loop = 0; (c = getchar()) != EOF && c != '\n' && loop < 15; loop++){			if (c >= '0' && c <= '9'){				strInputFloatingPoint[loop] = c;			}			else			{				error = 1;			}		}		if (error == 1){			printf("Wrong Entry\n");			error = 0;		} else {			break;		}	}	temp2 = atoi(strInputFloatingPoint);	temp2++;printf("temp2: %d\n", temp2);printf("loop: %d\n", loop);	intInputDividend = atoi(strInputDividend);	intInputDivider = atoi(strInputDivider);	division(intInputDividend, intInputDivider, floatingPointArray, temp2);	/*---------------------------------	 * Loop to print out the results	 * from the array	 *---------------------------------	 */		printf("\n");		printf("Answer: ");	for (loop = 0; loop < temp2; loop++){		if (loop == 1){			printf(".");		}		printf("%d", floatingPointArray[loop]);	}	printf("\n\n");	return 0;}void division(int intInputDividend, int intInputDivider, int floatingPointArray[], int count){	double result, divider, dividend, remainder;													/* standard variable initalisation - pretty self explanatory */	int loop, count1;	count = 0;	dividend = intInputDividend;	divider = intInputDivider;	count = count + 1;	while ((result = dividend - divider) != 0 && count != 0 ){	/* checks to see if the remainder isn't equal to zero, and it has not reached the length of required doubleing points*/		if (result < 0){			floatingPointArray[count1] = 0;			while (count != 0){				for (loop = 1; (result >= divider); loop++){					result = result - divider;							/* calculates the actual remainder from each time round the loop */				}				floatingPointArray[count1+1] = loop;				count = count -1;				++count1;			}			return;		}		for (loop = 1; (result >= divider); loop++){			result = result - divider;							/* calculates the actual remainder from each time round the loop */		}		remainder = result;		floatingPointArray[count1] = loop ;						/* stores the result into the array */		count = count - 1;										/* decrement count */		++count1;												/*increment second counter */		if (remainder == 0){			while (count != 0){				floatingPointArray[count1] = 0 ;				count = count -1;				++count1;			}			return;		}		if (remainder < 1){			dividend = remainder;		}		if (remainder > 100 && remainder < 1000){			dividend = remainder * 100;		}		if (remainder > 0 && remainder < 100){			dividend = remainder * 10;								/*prepare the dividend for the next time around the loop */			printf("dividend %f\n", dividend);		}		if (remainder > 1000 && remainder < 10000){			dividend = remainder * 1000;		}	}}