473,611 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

8 New Member
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 3117
weaknessforcats
9,208 Recognized Expert Moderator Expert
What kind of chart are you to display?
Dec 4 '08 #2
whodgson
542 Contributor
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
3051
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 the user to define the value for each dimension in the array. It will output the High value, the Low value and the average of them all. I seem to have a bit of a problem. I can't seem to get a working function for finding the lowest value of...
0
3428
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 Pentagjetvedeh karuvificials madhla reachathe strategy in karkun campaign deshatinst terrorism. "mudivae maretu winning or losing karkun global varti jetvedeh terror?" Mr. Rumsfeld adugued in a recent memormariyuum. vede velli jetvedeh madhla...
3
3806
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 out. note: I only in intro C++ which is about to be finished by the next two weeks. The topic which I am on in my book is "POINTERS" Text from the book:
9
2345
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 delimiting characters can be specified on the command line. The default delimiting characters built into the program are space, newline, tab, carriage return, form feed, vertical tab, comma and null. If a 'u' or 'U' is specified as the last command line...
3
2307
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
2328
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
2534
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 run, However, i simply created this program in arrays and it runs good except i cant figure out how to compute the standard deviation. The coding is below. Any help will be appreciated. 1) The Program will prompt the user for six grades to be...
1
3557
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 run, However, i simply created this program in arrays and it runs good except i cant figure out how to compute the standard deviation. The coding is below. Any help will be appreciated. 1) The Program will prompt the user for six grades to be...
0
1235
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
8097
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8596
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8240
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7038
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6072
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4042
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2546
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.