I am trying to fill my 2D array with random numbers, but I get random big numbers rather than random numbers between 1 and 4
Here is what I am trying to accomplish:
- When user is asked: Enter a number between 1 and 12 : (user enters) 5
- The user will get a 5x5 Array since they entered 5
- Then I want to fill the 2D array with random numbers between 1 and 4
Here is my code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
using namespace std;
double Atemp = 0;
double Utemp = 0;
double Working = 0;
double Total = 0;
char Answer = 'x';
int Umain;
const int LG_GRID = 12;
const int ROWS = 3;
const int COLS = 3;
const float DIV = 4;
typedef float Table[ROWS][COLS];
void displayOverview ();
void playOrQuit();
void promptNumber();
void outputSubSquare(Table table, int x, int y);
void fillTableWithRands(Table table);
void outputTable(Table table);
int main(){
    displayOverview();
    playOrQuit();
    srand(time(NULL));
    Table myTable;
    fillTableWithRands(myTable);
    outputTable(myTable);
    return 0;
}
void displayOverview(){
}
void playOrQuit(){
    string playOrNot;
    cout << "If you want to play please press 'p' for play, and 'q' if you wish to quit\n";
    cin >> playOrNot;
    if(playOrNot == "p"){
        cout << "Awesome, lets start playing !!! \n";
    }if(playOrNot == "q"){
        cout << "Alright then, see you soon !!\n";
        exit(0);
    }if(playOrNot != "p" && playOrNot != "q"){
        cout << "Invalid entry !!\n";
        exit(0);
    }
}
void promptNumber(){
    do{
      cout << "Please Enter numbers between 1 and 12: ";
      cin >> Umain;
      if(Umain <= 12){
            for (Utemp = Umain; Utemp > 0; Utemp--){
          cout << "Please enter a number between 1 and 4: ";
          cin >> Atemp;
            }
      }else{
    cout << "Not within limit :(\n";
      }
    }while (Answer == 'y');
}
void fillTableWithRands(Table table){
  for(int i = 0; i<ROWS; i++){
    for (int j = 0; j<COLS; j++){
      table[i][j]  = (float)(rand())*DIV;
    }
  }
}
void outputTable(Table table){
  for(int i = 0; i<ROWS; i++){
    for (int j = 0; j<COLS; j++){
      cout << table[i][j] << "\t";
    }
    cout << endl;
  }
}
