---------------------------- // Without arrays: BAD int grade0 = 67 int grade1 = 71 int grade2 = 99 // ... and so on int grade9 = 86 double average = 0 average = average + grade0 average = average + grade1 // dying whale noises... average = average + grade9 average = average / 10 print "Grades:" print grade0 print grade1 // too lazy, can’t cope… ---------------------------- // Once we've learned more about arrays grades[0] = 67 grades[1] = 71 grades[2] = 99 // okay, still have to do this grades[9] = 86 double average = 0 for (int i = 0; i < 10; i++){ average = average + grades[i] } average = average / 10 print Grades:" for (int i = 0; i < 10; i++){ print grades[i] } ---------------------------- int grades[10] grades[1] = 76 double prices[20] price[3] = 4.99 String names[5] name[2] = "Doris" ---------------------------- int grades[10] grades[ 0 ] = 74; grades[1] = 99; grades[8] = 89; grades[9] = 77; grades[10] = 51; ---------------------------- String words[5] print words[3] // maybe error or garbage value String animals[5] animals[0] = "cat" animals[1] = "dog" animals[2] = "hamster" animals[3] = "budgie" animals[4] = "snake" String zooAnimals[5] = {"elephant", "zebra", "hippo", "penguin", "aardvark"} ---------------------------- int numlist[20]; int x; x = 33; numlist[2] = 40; numlist[19] = x; x = numlist[2]; numlist[3] = numlist[2]; numlist[0] = numlist[2] + numlist[19]; numlist[3] = numlist[3] + numlist[0] * 2; ---------------------------- String numlist[20]; String s; s = "dog"; numlist[2] = "cat"; numlist[19] = s; s = numlist[2]; numlist[3] = prompt "what animal?" if ( numlist[3] == numlist[2]) then print "already have a cat!" endif ---------------------------- double prices[10]; prices[0] = 4.99 prices[1] = 6.99 prices[2] = 19.99 int which = prompt "which item (1 to 10)?" which = which – 1 // adjust human to programmer // check for safe index if (0 <= which AND which < 10) then int userprice = prompt "What price?" prices[which] = userprice endif ---------------------------- String week[7] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"} week[0] = "OH NO!" week[4] = "YAY" week[5] = "SLEEP" ---------------------------- double week[7] int day = prompt "What day of the week" day = day -1 // convert from human to programmer numbers double amount = prompt "How much?" week[day] = amount // could be error, we didn't check value of day ---------------------------- int weeklength = 7 double week[weeklength] int day = prompt "What day of the week" day = day -1 // convert from human to programmer numbers double amount = prompt "How much?" while (day >= 0 AND day < weeklength) week[day] = amount day = prompt "What day of the week" day = day -1 // convert from human to programmer numbers amount = prompt "How much?" endwhile ---------------------------- ----------------------------