Computer Science Canada Using Arrays? |
Author: | SAValkyrie [ Thu Nov 01, 2012 9:33 pm ] | ||
Post subject: | Using Arrays? | ||
I have to make a program that can average a series of marks. Before I enter the series, I have to have the program ask the user how many marks there are in the series then read it in. This is my coding till now
So I got the part where program asks you a number of marks. However, I use put marks/number part to average the marks but the answer it gives me is the only for the last mark that a user inputted. So, I wonder is there a way to do this by not using arrays because I think arrays can be used here... If it's not possible without arrays can you guys plz write an example using the arrays? thanks.[/syntax] |
Author: | Insectoid [ Thu Nov 01, 2012 9:36 pm ] |
Post subject: | RE:Using Arrays? |
You don't need an array. Forget about programming for a second and think about how you calculate averages with regular boring old math. There's really only one step that you're missing, and it's the same if you use an array or not. |
Author: | Dan [ Thu Nov 01, 2012 9:40 pm ] |
Post subject: | RE:Using Arrays? |
I moved your topic to Turing Help. Insectoid is correct, this problem does not need an array. Also you might want to try using a for loop rather then using "exit when", it would make your code a bit more readable. |
Author: | SAValkyrie [ Thu Nov 01, 2012 10:23 pm ] | ||||
Post subject: | Re: Using Arrays? | ||||
Well.... when you want to find the average of several marks. You add them all up and divide by a number of marks(in this case) you inputted...
I tried doing it with using for loop. I can do that but the prob is my late sentence I would normally do this for average..
but i cant seem to do that in this case ?![/syntax] |
Author: | Dan [ Thu Nov 01, 2012 10:27 pm ] |
Post subject: | RE:Using Arrays? |
Well if you have a set of marks (10, 3, 50, 55, 40) then doing: x = 0 x += 10 x += 3 x += 50 x += 55 x += 40 Then the average is x/5. How would you make a program that does the same thing but input the marks rather then have them hard coded and allow any number of marks to be put in? |
Author: | SAValkyrie [ Thu Nov 01, 2012 10:31 pm ] | ||
Post subject: | Re: Using Arrays? | ||
Oh I got it... it was easier than i thought.. I am starting to get ahold of turing so thanks for help guys ![]() |