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