How to display Arrays on screen

Hi..im kind of new to C++, studying it in school right now..Using visual studio 2005, and the schools 'own' library called 'Gwin', which uses commands like 'Gwin.writeText(x,y,"This will write text on screen ")' and 'Gwin.getInt()' + Gwin.getDouble() to get user inputs [int or double]


Anyway were doing arrays right now, this program basically asks the user to input 6 values for days 0-5 [between 1-100] then displays the average. After this stage im trying to display all the values of the array (so we get the 6 entered values displayed on screen) and I cant seem do to this.


This is what I have atm:

Sorry if its hard to read due to Gwin library, but basically

-int pollution_level[6] is the array
-int counter is the day number (e.g Day 0 Day 1...Day 5)
-int movement is just another int - same as counter but using this to display the array
-parts in bold is where im trying to display the array on screen, trying to get something like

Day element
0 45
1 3
2 78
3 1
4 99
5 whatever else we entered intitally








int main()
{
int pollution_level[6];
int average=0;
int counter =0;
int movement=0;
int y = 35;
// Clear the Gwin window
Gwin.clear();

while (counter<6)
{
Gwin.clear();
//prompt the user
Gwin.writeText(0,20,"Enter pollution level for day ");
Gwin.writeInt(190,20,counter); //tell him/her the day required
Gwin.writeText(200,20," range (1-100): "); //and the range
pollution_level[counter] = Gwin.getInt(); //now get the value into an array element


while ((pollution_level[counter]>100) ||(pollution_level[counter]<1))
{
Gwin.clear();
Gwin.writeText(185, 35, "Input not in range of 1-100, enter again : ");
pollution_level[counter] = Gwin.getInt();
}

average = average + pollution_level[counter]; //calculate the average
counter++;

}



Gwin.clear();
Gwin.writeText(0, 20, "The average pollution level over those 6 days was :");
Gwin.writeInt(400, 20,average/6);


while (movement<6)
{
Gwin.writeText(65,160, "Day number");
Gwin.writeInt(75,160+y,movement);
Gwin.writeInt(115,160+y,pollution_level[6]);
movement++;
y=y+20;

}


// Finally, wait for a key to be pressed
Keyboard.getch();

return 0;
}



Any help would be apreciated, thanks
I dont understand that gwin stuff, but generaly:

1
2
3
4
5
const int SIZE; //6 in your case
int myArray[SIZE]; //the array
...//initialize values
for (int i=0;i<SIZE;i++) //go through all elements
    cout<<i<<'\t'<<myArray[i]<<endl; //print indexnumber and value 


Hope that helps.
Last edited on
Topic archived. No new replies allowed.