473,406 Members | 2,336 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,406 software developers and data experts.

Having some trouble with a multi-dimenstional array

I am trying to write a program that takes a test score into an array and prints out the scores into a histogram, I can't figure out how to get count each test score and remember it to turn it into the histogram at the end.

All help is appreciated.
Nov 1 '06 #1
1 1207
Sorry I forgot to add my source code, here it is
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int numberOfTests = 1;
  5. int read (int scores [][numberOfTests]);
  6. void countScores (int studentScore[][numberOfTests], int numberOfStundents, int counts[101]);
  7. void writeHistogram (int counts[101]);
  8.  
  9. int main ()
  10. {
  11.     int studentScore[30][numberOfTests];
  12.     int counts[101];
  13.     int numberOfStudents = read(studentScore);
  14.     countScores(studentScore, numberOfStudents, counts);
  15.     cout << endl;
  16.     writeHistogram(counts);
  17.     return 0;
  18. }
  19.  
  20. int read(int scores[][numberOfTests])
  21. {
  22.     int numberOfStudents = 0;
  23.     cout << "Enter the test scores (-1 to end): ";
  24.     for (int i =0; i <= numberOfTests-1; i++)
  25.     {
  26.         cin >> scores[numberOfStudents][i];
  27.     }
  28.     while (scores[numberOfStudents][0] != -1)
  29.     {
  30.         numberOfStudents++;
  31.         cout << "Enter the test scores (-1 to end): ";
  32.         for (int i = 0; i <= numberOfTests-1; i++)
  33.         {
  34.             cin >> scores[numberOfStudents][i];
  35.         }
  36.     }
  37. return numberOfStudents;
  38. }
  39.  
  40. void countScores (int studentScore[][numberOfTests], int numberOfStudents, int counts[101])
  41. {
  42.      counts[0]=0;
  43.      counts[1]=0;
  44.      counts[2]=0;
  45.      counts[3]=0;
  46.      counts[4]=0;
  47.      counts[5]=0;
  48.      counts[6]=0;
  49.      counts[7]=0;
  50.      counts[8]=0;
  51.      counts[9]=0;
  52.      counts[10]=0;
  53.      counts[11]=0;
  54.      counts[12]=0;
  55.      counts[13]=0;
  56.      counts[14]=0;
  57.      counts[15]=0;
  58.      counts[16]=0;
  59.      counts[17]=0;
  60.      counts[18]=0;
  61.      counts[19]=0;
  62.      counts[20]=0;
  63.      counts[21]=0;
  64.      counts[22]=0;
  65.      counts[23]=0;
  66.      counts[24]=0;
  67.      counts[25]=0;
  68.      counts[26]=0;
  69.      counts[27]=0;
  70.      counts[28]=0;
  71.      counts[29]=0;
  72.      counts[30]=0;
  73.      counts[31]=0;
  74.      counts[32]=0;
  75.      counts[33]=0;
  76.      counts[34]=0;
  77.      counts[35]=0;
  78.      counts[36]=0;
  79.      counts[37]=0;
  80.      counts[38]=0;
  81.      counts[39]=0;
  82.      counts[40]=0;
  83.      counts[41]=0;
  84.      counts[42]=0;
  85.      counts[43]=0;
  86.      counts[44]=0;
  87.      counts[45]=0;
  88.      counts[46]=0;
  89.      counts[47]=0;
  90.      counts[48]=0;
  91.      counts[49]=0;
  92.      counts[50]=0;
  93.      counts[51]=0;
  94.      counts[52]=0;
  95.      counts[53]=0;
  96.      counts[54]=0;
  97.      counts[55]=0;
  98.      counts[56]=0;
  99.      counts[57]=0;
  100.      counts[58]=0;
  101.      counts[59]=0;
  102.      counts[60]=0;
  103.      counts[61]=0;
  104.      counts[62]=0;
  105.      counts[63]=0;
  106.      counts[64]=0;
  107.      counts[65]=0;
  108.      counts[66]=0;
  109.      counts[67]=0;
  110.      counts[68]=0;
  111.      counts[69]=0;
  112.      counts[70]=0;
  113.      counts[71]=0;
  114.      counts[72]=0;
  115.      counts[73]=0;
  116.      counts[74]=0;
  117.      counts[75]=0;
  118.      counts[76]=0;
  119.      counts[77]=0;
  120.      counts[78]=0;
  121.      counts[79]=0;
  122.      counts[80]=0;
  123.      counts[81]=0;
  124.      counts[82]=0;
  125.      counts[83]=0;
  126.      counts[84]=0;
  127.      counts[85]=0;
  128.      counts[86]=0;
  129.      counts[87]=0;
  130.      counts[88]=0;
  131.      counts[89]=0;
  132.      counts[90]=0;
  133.      counts[91]=0;
  134.      counts[92]=0;
  135.      counts[93]=0;
  136.      counts[94]=0;
  137.      counts[95]=0;
  138.      counts[96]=0;
  139.      counts[97]=0;
  140.      counts[98]=0;
  141.      counts[99]=0;
  142.      counts[100]=0;
  143.      counts[101]=0;
  144.          for (int i = 0; i < numberOfStudents; i++)
  145.     {
  146.  
  147.         for (int j = 0; j < numberOfTests; j++)
  148.             return;
  149.     }
  150. }
  151. void writeHistogram (int counts[101])
  152. {
  153.     counts[0]=0;
  154.      counts[1]=0;
  155.      counts[2]=0;
  156.      counts[3]=0;
  157.      counts[4]=0;
  158.      counts[5]=0;
  159.      counts[6]=0;
  160.      counts[7]=0;
  161.      counts[8]=0;
  162.      counts[9]=0;
  163.      counts[10]=0;
  164.      counts[11]=0;
  165.      counts[12]=0;
  166.      counts[13]=0;
  167.      counts[14]=0;
  168.      counts[15]=0;
  169.      counts[16]=0;
  170.      counts[17]=0;
  171.      counts[18]=0;
  172.      counts[19]=0;
  173.      counts[20]=0;
  174.      counts[21]=0;
  175.      counts[22]=0;
  176.      counts[23]=0;
  177.      counts[24]=0;
  178.      counts[25]=0;
  179.      counts[26]=0;
  180.      counts[27]=0;
  181.      counts[28]=0;
  182.      counts[29]=0;
  183.      counts[30]=0;
  184.      counts[31]=0;
  185.      counts[32]=0;
  186.      counts[33]=0;
  187.      counts[34]=0;
  188.      counts[35]=0;
  189.      counts[36]=0;
  190.      counts[37]=0;
  191.      counts[38]=0;
  192.      counts[39]=0;
  193.      counts[40]=0;
  194.      counts[41]=0;
  195.      counts[42]=0;
  196.      counts[43]=0;
  197.      counts[44]=0;
  198.      counts[45]=0;
  199.      counts[46]=0;
  200.      counts[47]=0;
  201.      counts[48]=0;
  202.      counts[49]=0;
  203.      counts[50]=0;
  204.      counts[51]=0;
  205.      counts[52]=0;
  206.      counts[53]=0;
  207.      counts[54]=0;
  208.      counts[55]=0;
  209.      counts[56]=0;
  210.      counts[57]=0;
  211.      counts[58]=0;
  212.      counts[59]=0;
  213.      counts[60]=0;
  214.      counts[61]=0;
  215.      counts[62]=0;
  216.      counts[63]=0;
  217.      counts[64]=0;
  218.      counts[65]=0;
  219.      counts[66]=0;
  220.      counts[67]=0;
  221.      counts[68]=0;
  222.      counts[69]=0;
  223.      counts[70]=0;
  224.      counts[71]=0;
  225.      counts[72]=0;
  226.      counts[73]=0;
  227.      counts[74]=0;
  228.      counts[75]=0;
  229.      counts[76]=0;
  230.      counts[77]=0;
  231.      counts[78]=0;
  232.      counts[79]=0;
  233.      counts[80]=0;
  234.      counts[81]=0;
  235.      counts[82]=0;
  236.      counts[83]=0;
  237.      counts[84]=0;
  238.      counts[85]=0;
  239.      counts[86]=0;
  240.      counts[87]=0;
  241.      counts[88]=0;
  242.      counts[89]=0;
  243.      counts[90]=0;
  244.      counts[91]=0;
  245.      counts[92]=0;
  246.      counts[93]=0;
  247.      counts[94]=0;
  248.      counts[95]=0;
  249.      counts[96]=0;
  250.      counts[97]=0;
  251.      counts[98]=0;
  252.      counts[99]=0;
  253.      counts[100]=0;
  254.      counts[101]=0;
  255.     for (int i = 101; i > 0; i--)
  256.     {
  257.  
  258.         for (int j = 0; j <= counts[i]; j++)
  259.         {
  260.             cout << i-1 << ":";
  261.             cout << " *";
  262.         }
  263.         cout << endl;
  264.     }
  265. }
  266.  
]
Nov 1 '06 #2

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

Similar topics

7
by: Erik Bethke | last post by:
Hello All, I have found much help in the google archives but I am still stuck... here is my code snippet: path = os.getcwd() path = path.decode('UTF8') Now the trouble is I am getting that...
1
by: ajackson | last post by:
i am having some trouble installing SQl server Reporting Services. well, in order to install the reporting services i have to install Service Pack 3a. so through my installation of package 3a i...
1
by: mr_burns | last post by:
hi there, Ive been having a few problems recently with this group. Im not sure if any of the other groups have been giving me trouble but recently this one has a couple of times, when attempting...
5
by: Lisa | last post by:
Hello, I am new to using recordsets, and i am completly stuck with this one. I am trying to use a multi select list box to write records to a table. Something in my code is causing the same...
12
by: Winbatch | last post by:
Hi, I'm trying to learn multithreading and it doesn't seem to be working for me. I have a feeling it has to do with the fact that I'm writing to files rather than to printf, but maybe not. ...
6
by: Hypo | last post by:
Im relatilvly new to a web programming in general, and here's the situation i have: I have a default page with dynamic content, and one button with onclick code something like this: { // do...
0
by: Jozef | last post by:
Hello, I'm having trouble with the download links on my web server. The error I'm getting is; CGI Timeout The specified CGI application exceeded the allowed time for processing. The server...
8
by: Flack | last post by:
Hey guys, In my app I have a bitmap where drawing is done and in the form's paint method I show the bitmap: private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
2
by: msridhar87 | last post by:
hi, am doing a multi server chat program using select()..in the client side i need to multiplex thei/p from server and stdin. #include <stdio.h> #include <sys/types.h> #include <sys/socket.h>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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.