Need help putting in displaying my rng to a table

So I'm trying to figure out how to put these set amount of marbles on the table and display the total of each color and the total of all the marbles on the bottom but it seems that I just cant figure it out (any help would be great)

the marbles go through rng and so does the 6 colors and the set amount of bags

// defining my variables 
int sum, colors, marbles, bags, r, o, y, g, b, p, total, num = 1,blue =0, red =0, orange =0, yellow =0, purple =0, green =0, count = 0, lower, upper, MAX_BAGS = 15, MIN_BAGS = 5,MIN_MARBLES = 120, MAX_MARBLES = 240;

string FILENAME = "cpp_prj_1744072";

// FUNCTION PROTOTYPES
void displayMessage(string str);
void getNumBags();
void displayTable();
void displayHeader();
void displayRow();
void rng();
void DisplayFooter();

// main program
int main() 
{
  displayMessage("hello");
  getNumBags();
  displayTable();
  displayMessage("GoodBye");
 
  
}

void displayMessage(string str)
{
  cout << str;

}  

void displayHeader()
{
  cout << setw(5) << "BAG" << setw(5) << "RED" << setw(5) << "ORG" <<  setw(5) << "YEL" << setw(5) << "GRN" << setw(5) << "BLU" << setw(5) << "PPL" << setw(5) << "TOT" << endl;
  cout << "---------------------------------------------\n" << endl;


}

void getNumBags()
{
  cout << "\n\nPlease enter the number of bags you want (Min value must be atleast 5 or greater) : ";
  cin >> lower;



  while(lower < 5)
  {
    cout << "\nYou entered :" << lower << " which is below the minimum amount please try this again" << endl;
  
     
    cout << "Please enter a number greater than 5 :"; 
    cin >> lower;
  }

  cout << "\n\nPlease enter the number of bags you want (Maximum value must be no larger than 15) : ";
  cin >> upper;
   
  while (upper > 15)
  {
    
    cout << "\nYou have entered a number that is not within the parameters" << endl; 

    cout << "Please enter a number that does not exceed the value of 15 :";
    cin >> upper;

  }
}    
  
void displayTable()
{
  srand(time(0));
  ofstream cpp_prj_1744072;
  cpp_prj_1744072.open("cpp_prj_1744072.txt");
  displayHeader();
  
  while (bags)
    displayRow();
    {
    

    }
  DisplayFooter();
  cout << "close the file here";

}

void displayRow ()
{
  static int id =1;
  rng();
  do
  {
    rng();
    switch(colors)
    {
    case 1:
      blue++;break; 
    case 2:
      red++;break; 
    case 3:
      orange++;break; 
    case 4:
      yellow++;break; 
    case 5:
      purple++;break; 
    case 6:
      green++;break;  
    default:
      cout << "invaild entry try once more";

    
    }

      sum = green + yellow + orange + purple + red + blue;
    
    
    id++;
  }
  while (marbles > sum);
  
  cout << num;
  cout << setw(5) << blue << setw(5) << red << setw(5) << orange << setw(5) << yellow << setw(5) << purple << setw(5) << green << setw(5) << sum << endl;

  id++;
}

void rng()
{
  bags = rand() % (upper + lower);
  marbles = rand() % (MIN_MARBLES + MAX_MARBLES);
  colors = rand() % (1 + 6);
}

void DisplayFooter()
{
  cout << "---------------------------------------------\n" << endl;
  cout << setw(5) << "TOT" << setw(5) << r << setw(5) << o <<  setw(5) << y << setw(5) << g << setw(5) << b << setw(5) << p << setw(5) << total << endl; 
}


Read more here: https://stackoverflow.com/questions/67479789/need-help-putting-in-displaying-my-rng-to-a-table

Content Attribution

This content was originally published by Erik at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: