I really don''t know how to do this...
Author |
Message |
PJ_69
|
Posted: Mon Apr 03, 2006 12:07 pm Post subject: I really don''t know how to do this... |
|
|
Does anybody have any idea of how to do this....This is an assignment I was assigned....really complicated...
Quote: Write a program that will read three integers from keyboard.
The three integers are then added together and the average is calculated.
The average is then output on the same line as the three integers formatted appropriately.
Modify the program to accommodate 12 sets of data (use a loop structure). A set being a group of three.
The program will also total all the first entries, all the second entries, and all the third entries of each set.
After all twelve sets of data have been entered then the average of first entries is calculated and printed out along with the average of the all the second entries and the third entries.
Hint: You will need a loop and three variables for the three entries. You will need 4 variables for adding up the totals and four more variables for the averages.
Your output will look like
"Please enter the three integers. Each integer has a space between them"
10 5 10
The total for the set is 25 and the average is 8.33
Please enter the three integers. Each integer has a space between them"
15 2 1
The total for the set is 18 and the average is 6.00
Etc.
The total for the first set is 25 and the average is 11.50.
The total for the second set is 7 and the average is 3.50.
The total for the third set is 11 and the average is 5.50.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
codemage
|
Posted: Mon Apr 03, 2006 12:47 pm Post subject: (No subject) |
|
|
The description is a bit confusing until you look at the example.
My advice would be, start coding so that your program looks like the example (using get statements for the input). When you get stuck, post what you've got. |
|
|
|
|
|
Delos
|
Posted: Mon Apr 03, 2006 1:40 pm Post subject: (No subject) |
|
|
A good approach to this will be to use 2-dimensional arrays. Check out [Turing Tutorials] for more info. If you really want to, you could use flexible arrays instead, but I'm not sure if your teacher would appreciate that level of difficulty for this assignment.
It's really not a difficult project, just will require carefully keeping track of variables.
For your final output, you way want to format it in a nice table, to make it easier on the eyes. Of coures, you can do this with pure ASCII text too, so that will not require you to use Draw.() commands.
For instance:
Text: |
Entry1 Entry2 Entry3
Sum 20 25 30
Mean 2 2.5 3
|
One thing I do find a little odd is that you're to provide summary values for each group of data (Entries 1-3) directly after each (i.e. "The total for the set is 25 and the average is 8.33 "). Personally, I'd do a similar table as above for that at the end of the entries, but then again I'm not your teacher.
Also, you should point out to your teacher that their naming is inconsistent. Initally, they define a "set" as "...a group of three [numbers]". Later, at the end of the programme, they provide the final summary values for each of the 1st, 2nd, and 3rd entries, but present it as "The total for the first set..."
This will really confuse students who actually take the time to read the instructions, since the 'set' being referred to is not the 'set' that was previously and explicitely defined. This should really read "The total for the first set of entries..." or thereabouts.
But yes, 2-dim arrays. |
|
|
|
|
|
MysticVegeta
|
Posted: Mon Apr 03, 2006 5:33 pm Post subject: (No subject) |
|
|
I dont really think you would need 2 dim arrays... Although you could use them but you would just confuse yourself. Do it like the descrip says, using 3 for input, 4 for sum and 4 for mean. Yes Delos is right to use arrays as that will save you much time and code but if it says how to do it in the descrip, then do it as it says |
|
|
|
|
|
Delos
|
Posted: Mon Apr 03, 2006 5:37 pm Post subject: (No subject) |
|
|
My reasoning was simple...using a 2-dim array allows the entire main programme to be compressed into 2 nested for-loops. Subsequent calculations can then be made in further for-loops using appropriate subscript manipulations. Using a series of 1-dim arrays, or worse a bunch of individual variables would just bulk up the code. |
|
|
|
|
|
MysticVegeta
|
Posted: Mon Apr 03, 2006 10:17 pm Post subject: (No subject) |
|
|
yeah I know thats why I said your code would save a lot of time but it looks like PJ_69 doesnt know 1 dim arrays, so 2 dims would just confuse him, thats why I said using vars like the thing said |
|
|
|
|
|
PJ_69
|
Posted: Tue Apr 11, 2006 2:02 pm Post subject: (No subject) |
|
|
Yes, I somehow finished it.....What do you think?
code: | %This program will
%This program was ****
%Variables
var _1, _2, _3 : array 1 .. 12 of int % Three numbers set as variables.
var total, tot1, tot2, tot3 : int := 0 % The total of the set, and the total of the
% first, second and third numbers in the set.
%12 Sets of numbers and the total and the average for each set
for a : 1 .. 12 % A loop (counted) from 1 to 12.
colour (2) % The color of the text is set to 2.
put "Enter the three integers for set #", a, ". Put a space between the numbers" % What to do
colour (black) % Text color is set to black.
get _1 (a), _2 (a), _3 (a) % Receives 3 numbers from the set.
total := _1 (a) + _2 (a) + _3 (a) % Total is calculated for the 3 numbers.
colour (3) % Color set to 3.
put "Total for set#", a, " is ", total, " average is ", total div 3 % Total + avg. of set
tot1 := tot1 + _1 (a) % Total for the first number in each set is calculated.
tot2 := tot2 + _2 (a) % Total for the second number in each set is calculated.
tot3 := tot3 + _3 (a) % Total for the third number in each set is calculated.
end for % Counted loop ends.
% Color
colour (3) % Color of text is 3.
% Average plus the total of each set.
put "First number totals in 12 sets is... ", tot1, " and average is ", tot1 div 12
put "First number totals in 12 sets is... ", tot2, " and average is ", tot2 div 12
put "First number totals in 12 sets is... ", tot3, " and average is ", tot3 div 12 |
|
|
|
|
|
|
TokenHerbz
|
Posted: Tue Apr 11, 2006 2:30 pm Post subject: (No subject) |
|
|
i suppose its ok, though id use better variables. not that it matters in a small program like this though.
try to redo it now, useing a function. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|