C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-17-2009, 02:57 PM   #1
Registered User
 
Join Date: Feb 2009
Posts: 19
Help for my output array

Hi Guys, I having trouble with my output array. The system works fine, in that it takes input from the user and runs the correct logic and then ouputs it.

I have decided to include an output array, so; 1) The user selects the logic gate they want to test.
2) The user then selects how many inputs they would like.
*3) I have just decided to add this in, the user then selects how many outputs they would like.
4) The user then sets the values for the inputs.

What I am having a problem with now is that I would like the system to printf() the output as many times specified by the user.

eg, An AND gate has been selected, and 2 inputs have been declared and 3 outputs have been declared, the input values have been assigned to the input array. Once the gate has applied the bitwise operator, it outputs the response to the command prompt. I want it to display as so; Output = [1,1,1]. Instead of just Output = 1 or 0, I want it to output as many times as the user specified for the output array.

Here is what I have;
Code:
...int and(int n, int o)
{
	printf("\nPlease Set The Values For Your Inputs: ");
	int array[n]; ..input array
	int output[o]; //the output array

	int i = 0;
	for (i = 0; i < n; i++){
		printf("Enter input %d:", i);
		scanf("%d",&array[i]);
		while(array[i]!=0 && array[i]!=1){
			printf("Value must be 0 or 1. Please try again:\n");
			scanf("%d",&array[i]);
		}
	}

	int result = array[0];
	for(i = 1; i < n; i++)
	{
	   result &= array[i];
	}

	printf("\nOuptut = %d\n", result);

	/*int j = 0;
	for (j=0; j < o; j++){
		printf("%d", output[j]); //Just to see if it worked, but nope
	}*/
Thanks
qwertysingh is offline   Reply With Quote
Old 02-17-2009, 03:08 PM   #2
subminimalist
 
MK27's Avatar
 
Join Date: Jul 2008
Location: NYC
Posts: 3,946
How 'bout another "for" loop nesting from here:
Quote:
Code:
		}
	}

	int result = array[0];
	for(i = 1; i < n; i++)
Of course maybe then you want to move the declaration up.
__________________

Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS
MK27 is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Output an array in a textbox Diablo02 C# Programming 5 10-18-2007 03:56 AM
Array output strange swgh C++ Programming 1 12-09-2006 06:58 AM
Class Template Trouble pliang C++ Programming 4 04-21-2005 04:15 AM
Merge sort please vasanth C Programming 2 11-09-2003 12:09 PM
Struct *** initialization Saravanan C Programming 20 10-09-2003 12:04 PM


All times are GMT -6. The time now is 08:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22