Multiplying Arrays of Different Sizes

I've reviewed the section on arrays on cplusplus.com, re-read the chapter in my textbook multiple times, and done a LOT of Googling. I still can't quite get this code right-but I also think there is some fundamental about arrays that I'm missing. I understand the theory, but writing useable code is another story. I'm including my code below, but if it's obvious to anyone what I am missing based on what I post, please clue me in on that or any resource that may be helpful.

What I'm trying to do is multiply my 1d array by my 2d array.

I've tried many things, including:
-looping through my one dimensional array, then the "rows" part of my 2 dimensional array-then multiplying those. I don't *think* this makes sense, but I figured it was worth a try.
-Storing my "rows" in a separate 1d array, then
totalSales+=((rowArray[rowChoice])*(seatPrice[index]));

Though I'm pretty sure I'm not supposed to do that, prompt doesn't specifically say but I get that impression.

-Multiplying the arrays directly, though that doesn't work either since of course the dimensions don't match.

I've also tried other things, but this likely gives an idea of how far off base I am. I can't use pointers in my program. In the interest of not posting 250 lines below, I'm only including the arrays-which are both user input. Please let me know if you need more code-I'm really grateful for any assistance I get!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//variable for number of seats per row	
const int SEATS=30;
//variable for number of rows in theatre
const int ROWS=15;
//variable setting available seats to #
char available='#';
//variable setting taken seats to *
char taken='*';
//seating chart definition
char display [ROWS][SEATS]; 
//variable for user input choosing row to purchase seats
int rowChoice;
//variable for user input choosing seat
int seatChoice;
//defining array to hold price for each row
double seatPrice [ROWS];
//variable for total number tickets sold
double totalSales;

//initializing 2d array
for (int j=0; j<ROWS; j++)
{
	//print rows
	for (int k=0; k<SEATS; k++)
	{
		//Set initial seats (whole array) equal to #
		display [j][k]=available;
	}	
}

//initializing 1d array
for (int index=0; index <ROWS; index++)
			{
		cout<<"Please enter prices for Row Number "<<(index+1)<<" : $";
				//user input row prices
				cin>>seatPrice [index];		
			}	

//calling function user input row choice
rowChoice=getRowChoice();
//calling function user input seat choice
seatChoice=getSeatChoice();
//update 2d array
display [rowChoice][seatChoice]=taken;

//This is where I tried the multiplication-multiplying display[rowChoice] by seatPrice[index] in many many different ways.
Last edited on
What multiplication?

With each seat sold, you just do
totalSales += seatPrice[rowChoice];

Don't forget to initialise totalSales to 0 to begin with.
I literally just put my palm to my face. Thank you, Salem...I think I've been making this much harder than it actually is. I really can't thank you enough for your help!!!
Topic archived. No new replies allowed.