![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 19
| Help for my output array 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
}*/
|
| qwertysingh is offline | |
| | #2 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,946
| How 'bout another "for" loop nesting from here: Quote:
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |