#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
srand(time(NULL)); //For generate random price of item each launch of program
int numOfSalesman = 5;
int numOfItems = 10;
//2d array to store salesman's list of items prices as rows. One row for each salesman
int** salesmansArray = new int*[numOfSalesman];
for(int i = 0; i < numOfSalesman; i++) {
salesmansArray[i] = new int[numOfItems];
}
//Filling the arrays
for(int i = 0; i < numOfSalesman; i++) {
for(int j = 0; j < numOfItems; j++) {
salesmansArray[i][j] = rand() % 20; //Generating random prices (from 0 to 19)
}
}
//Printing the result
for(int i = 0; i < numOfSalesman; i++) {
cout << "salesman " << i << ": ";
for(int j = 0; j < numOfItems; j++) {
cout << salesmansArray[i][j] << " ";
}
cout << endl;
}
return 0;
}
Comments
Leave a comment