By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,171 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,171 IT Pros & Developers. It's quick & easy.

Having some trouble with a multi-dimenstional array

P: 3
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
Share this Question
Share on Google+
1 Reply


P: 3
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

Post your reply

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