A Class, an int array and a for loop walked into the bar....then they got stuck.
Hello everybody!
I've got a problem with the code below and would appreciate any help that you could give me.
The problem is that I have a class called "Class_1" and inside I have multiple int arrays which will store the values. (I know this is a bad way to do it but its the easiest way for me so far so I'm trying to stick with it).
I have the user input the entries for each int and it goes into the array and everytime they finish the position in the array increases.
This is where the screwy-ness occurs. When I attempt to display them in a for loop it doesnt show the values, instead it shows what I assume to be the memory address or something except it seems to be the same value....
Code:
class Class_1{
private:
public:
~Class_1(){};
Class_1(){};
// void set_values(...);
void disp_values(Class_1 object);
int _one[50], _two[50], _three[50], _four[50];
string _five[50];
/* ..............................
*/
void new_entry(Class_1 object){
cout << "\n One: ";
cin >> object._one[num];
cin.ignore();
cout << "\n Two: ";
cin >> object._two[num];
cin.ignore();
cout << "\n Three: ";
cin >> object._three[num];
cin.ignore();
cout << "\n Four: ";
cin >> object._four[num];
cin.ignore();
cout << "\n Five: ";
cin >> object._five[num];
cin.ignore();
num++;
cout << "\nEntry " << nPacket << " created.";
}
/*...........................................
*/
void Class_1::disp_values(Class_1 object){
int row=0;
cout << "\nOne \tTwo \tThree \tFour \tFive\n"
"------------------------------------";
for (row = 0; row < num; row++)
{
cout << endl << object._one[num] << "\t" << object._two[num];
cout << "\t" <<object._three[num] << "\t" << object._four[num];
cout <<"\t" << object._five[num];
}
cout << "\n------------------------------------\n";
cout << endl << num << " number of values.\n\n";
}
//For loop loops my array and displays the values in the corresponding position
//also the global variable "num" simply keeps track of the number of entries
So if anyone could help me out it would be brilliant! Also, if I havent given enough information just say and I'll try and provide some more info. Thanks in advance everybody!
Shini