Multidimensional arrays
dduardo said:
Please post your C++ questions or comments here for Tutorial 1.
I am having trouble getting my multidimensional array to do what I want it to do. Here is an exmple
of how I want this to look and how it will work.
row 1) Part Description | Part number //this is multidemsional array PD( row 1,columns 1-18 ), m array P#
row 2) Cam | 2110 // PD [1][0-4],Cam[1][0-4]
row 3) air filter | 1111 // PD [2][0-10],cam[2][0-4]
ect
My goal is on the first time the order function is entered to have row 1 and 2 display, the 2nd time the order function is entered rows 1,2,3 will display, the third rows 1,2,3,4 ect. Also the array will only display addresses not what it is supposed to. I know this is not an easy thing to do but I am not able to think of any other way to show all of the ordered items. Helllllllllllp plllllllllllllllease...
here is the code I have.
#include <iostream>
#include <iomanip>
#include <ctype.h>
#include <stdlib.h>
using namespace std;
void partsorder(char order[]);
void list(char order[]);
int zz = 0;
const int ROWS = 50;
const int COLS = 50;
const int CAM = 20;
int main()
{
char shaft[CAM]="";
do
{
cout << "The cam number is 2110. The cam kit number is 2110k. Please enter\n"
<< "the approiate part number ";
cin.getline(shaft,CAM);
if (shaft[0] != 0) //if shaft is not null then goto
list(shaft);
}while(shaft[0] != 0);
}
void list(char order[])
{
if (zz == 0){
cout << " | Part Description |" << " Part # |\n ";
partsorder(order);
}
else {
partsorder(order);
}
}
void partsorder(char order[])
{
int num = 0, e = strlen(order);
num = atoi(order);
char c[CAM] = "Cam";
char ck[CAM] = "Cam kit";
char b,pd[ROWS][COLS];
zz++;
switch (num)
{
case 2110:
if (e == 4){
for(int y = 0; y < COLS; y++){
pd[zz][y]=c[y];
}
//strcpy(pd,c);
b = ' ';
//cout << "Please enter the quantity -->";
//cin >> q;
//price = 86 * q;
break;
}
else if (e == 5) {
for(int y = 0; y < COLS; y++){
pd[zz][y]=c[y];
}
//strcpy(pd,ck);
b = 'k';
//cout << "Please enter the quantity -->";
//cin >> q;
//price = 136 * q;
}
}
int x = 0;
for(int y = 0; y < COLS; y++){
cout << pd << endl;
for (x = 0; x <= zz; x++){
//cout << " | " << setw(16)<< setiosflags(ios::left) << pd [x][y]<< " | " << setw(5) << num << b << endl;
}
}
}