I'm trying my hardest to simulate a Buffer and producer and I did it with if statements, well the loop is acting funny it prints out numbers out of order, I want it to print out just 1,2,3,4,5 representing each address in the Buffer when it prints out these numbers its representing that address is full. Should I be using a switch statement instead if not how do I keep the loop from printing out all five if statement results 5 time times in a row because its printing five random numbers 5 X 5 times, i would appreciate any advice
here's my code
I know my if statements are disorganized
but what I'm trying to do is store a number in that address ex.myBuffer[0]=1
cout<<myBuffer[0];
and so on!!!!!
I have no idea what you think a "buffer and producer" are, but that's some seriously goofy logic you've got going on there. Perhaps you should look up the use of 'else' in combination with if, or maybe just be a little more straightforward:
#include <iostream>
usingnamespace std;
constint N=5;
int myBuffer[N];
void producer()
{
for ( int i = 0; i < N; ++i )
myBuffer[i] = i+1 ;
for ( int i = 0; i < N; ++i )
cout << myBuffer[i] << endl ;
}
int main(){
producer();
system ("PAUSE");
return 0;
}