473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Help finding the average of reach row in a 2D array function

im currently working on a assignment, where you have 3 monkeys that are feed for 7 days. You have to use a 2D array to gather the info. display like a chart, and find the average eaten each day.

This is the code I have so far. I only need help with displaying it as a chart and finding the average. Please ^.^


Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void getFood(double arrayPound[3][7]);
  8. void displayFood(double arrayPound[3][7]);
  9. void sortLeast(double arrayPound[3][7]);
  10. void sortGreatest(double arrayPound[3][7]);
  11. void sortAverage(double arrayPound[3][7]);
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15. double arrayPound[3][7];
  16.  
  17. getFood(arrayPound);
  18. cout << endl;
  19.  
  20. displayFood(arrayPound);
  21. cout << endl;
  22.  
  23. sortAverage(arrayPound)
  24. cout << endl;
  25.  
  26. sortLeast(arrayPound);
  27. sortGreatest(arrayPound);
  28.  
  29.  
  30.  
  31. system("PAUSE");
  32. return EXIT_SUCCESS;
  33. }
  34.  
  35. void getFood(double arrayPound[3][7])
  36. {
  37. double pound = 0;
  38.  
  39. cout << "Food for the monkeys." << endl;
  40. cout << endl;
  41.  
  42. for(int i = 1; i < 4; i++)
  43. {
  44. for(int u = 1; u < 8; u++)
  45. {
  46. cout << "Please enter the amount feed to monkey " << i << " on day " << u << " :";
  47. cin >> pound;
  48.  
  49. while((cin == 0) || (pound < 0))
  50. {
  51. cin.clear();
  52. cin.ignore(10000, '\n');
  53. cout << "Please enter the amount feed to the monkey: ";
  54. cin >> pound;
  55. }
  56. arrayPound[i][u] = pound;
  57. }
  58. }
  59.  
  60. }
  61.  
  62. void displayFood(double arrayPound[3][7])
  63. {
  64. double pound;
  65.  
  66. cout << "Total food eaten across all 7 days." << endl;
  67. cout << endl;
  68.  
  69. for(int i = 1; i < 4; i++)
  70. {
  71. for(int u = 1; u < 8; u++)
  72. {
  73. cout << "The amount eaten by monkey " << i << " on day number " << u << " was: " << arrayPound[i][u] << endl;
  74. }
  75. }
  76. }
  77.  
  78. void sortLeast(double arrayPound[3][7])
  79. {
  80. double leastVal = arrayPound[0][0];
  81.  
  82. for(int i = 1; i < 4; i++)
  83. {
  84. for(int u = 1; u < 8; u++)
  85. {
  86. if(arrayPound[i][u] < leastVal)
  87. {
  88. leastVal = arrayPound[i][u];
  89. }
  90. }
  91.  
  92. }
  93. cout << "The least amount was eaten: " << leastVal << endl;
  94. }
  95.  
  96. void sortGreatest(double arrayPound[3][7])
  97. {
  98. double greatestVal = arrayPound[0][0];
  99.  
  100. for(int i = 1; i < 4; i++)
  101. {
  102. for(int u = 1; u < 8; u++)
  103. {
  104. if(arrayPound[i][u] > greatestVal)
  105. {
  106. greatestVal = arrayPound[i][u];
  107. }
  108. }
  109. }
  110. cout << "The greatest amount was eaten: " << greatestVal << endl;
  111. }
  112.  
  113. void sortAverage(double arrayPound[3][7])
  114. {
  115. double dailyAvg;
  116.  
  117. for(int u = 1; u < 8; u++)
  118. {
  119. ( arrayPound[1][u] + arrayPound[2][u] + arrayPound[3][u] ) / 3 = dailyAvg;
  120. }
  121.  
  122. cout << "The average eaten by the monkeys on day " << u << " was: " << dailyAvg << endl;
  123.  
  124. }
  125.  
Dec 4 '08 #1
2 3106
weaknessforcats
9,208 Expert Mod 8TB
What kind of chart are you to display?
Dec 4 '08 #2
whodgson
542 512MB
I haven't analysed your code to get some sense of the underlying algarithm (please use code tags) but I question the need for 5 2d arrays as an over complication. Have you given any thought to using just one array splitting monkeys and days and performing the required data manipulation by successive traverses?
Dec 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Michael Warner | last post by:
hey guys, I am having a bit of an issue with a project I'm doing. Basically what it will ultimately end up able to do is that it will accept set up a dynamic array based on user input and allow...
0
by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
9
by: santosh | last post by:
Hello all, I've put together a small program to count the number of characters and 'words' in a text file. The minimum length of a word, (in terms of no. of characters), as well as word...
3
by: C++Geek | last post by:
I need to get this program to average the salaries. What am I doing wrong? //Program to read in employee data and calculate the average salaries of the emplyees.
1
by: thebrainmore | last post by:
could someone help with my average and sort functions in this program #include <iostream.h> //funtion prototypes int FindLowNum(int , int ); int FindHighNum(int , int);
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
1
by: sparkid | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: JuAn2226 | last post by:
hi this my code Private Sub Form_Load() car_count = 0 Cumulative_Speed = 0 End Sub Private Sub Timer1_Timer() Dim tmpNumber As Integer
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.