0

Good evening.

I am hoping to get some help. I go to University of Phoenix and we were assigned a project. This is possibly the worst class I have ever had. They explain nothing relevant to the assignments. I have spent a week trying to figure this out and maybe I am just searching this wrong. I cannot figure out how to link the array[5][5] to the random function (they must be random numbers). I cannot figure out how to populate the array in such a way that I can calculate average and totals of each row. It must be formatted like this for each row:
Row 1
Total =
Average =

The code I have so far, which is probably really wrong, is this:

#include "stdafx.h"
#include<iostream>
#include<ctime>

using namespace std;

int main()
{
  srand(time(NULL));
  int rantab[5][5] = { rand() % 89 + 10 };
  int i, m;

  for(int i = 0; i < 5; i++);
  {
    for (int m = 0; m < 5; m++);
  }
  cout << rantab[i][m];

  return 0;
}

Any help I can get is appreciated. I have no idea where to go from here, if I am even correct so far. I love the c++ I got to learn in C++ without fear but this class just sucks all the fun and life out of it. Thank you again.

pgngp
  • 1,552
  • 5
  • 16
  • 26
Chris
  • 21
  • 1
  • 2
  • 2
    1) Take the semicolons off the end of your for loops. This causes the for loop body to be empty as a single semicolon is an empty statement. 2) Move the initialization of each element of rantab inside the inner for loop. 3) Your statement `cout << rantab[i][m]` will be accessing the array out of bounds and will cause undefined behavior because i and m will both be 5 outside the loops. You probably want to move this statement inside the inner loop. – MFisherKDX Mar 14 '18 at 00:33
  • Don't worry about it. Full-blown universities barely teach people how to program so you're not doing much worse. [Pick an introductory book from here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) and get a copy. Work through it, then move on to other books that either interest you or seem relevant. You may find Effective and Exceptional books live up to their names. They are effective and exceptional. – user4581301 Mar 14 '18 at 04:20
  • Forget about your assigned project. You should train yourself some C/C++ knowledge first. It's quite touch at first, but it's worth. http://www.learncpp.com/ I think you can handle this project yourself after 5-6 hours going through the C/C++ tutorial. – Ngo Thanh Nhan Mar 14 '18 at 06:38

1 Answers1

0

Try running a for loop inside a for loop to generate the random ints. Something like:

for (int i = 0; i < 5; i++) 
    for (int j = 0; j < 5; j++) 
        ranTab[i][j] = rand() % 89 + 10;

You can use those 2 loops to find the average, too.

MFisherKDX
  • 2,840
  • 3
  • 14
  • 25
DimosthenisK
  • 61
  • 1
  • 6