Hello all,
I am new here to cplusplus.com and I was hoping you guys could answer a question of mine. So I'm very very new to c++, but have had ample experience in PHP, and some Java.
So I have to make this program that asks a user how many rows and columns they would like in an array and then I have to ask them for the numbers they would like to put in that array. Then I have to take those numbers and find which row has the highest sum. I am capable of doing that, but I'm having trouble with getting the structure down.
So I decided I wanted to use vector's since they apparently are much easier to use than array's and here is what I've got :
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 48 49 50 51 52 53 54
|
#include <iostream>
#include <vector>
using namespace std;
class Calculator
{
int rows, columns;
public:
void GetData()
{
cout << "How many rows would you like? ";
cin>> rows;
cout << "How many columns would you like? ";
cin >> columns;
vector <int> < vector<int> > multiarray(rows, vector<int> columns);
for (int curRow = 0; curRow < rows; curRow++)
{
switch(curRow + 1) {
case 1:
cout << "Please enter numbers for the 1st row : ";
break;
case 2:
cout << "Please enter numbers for the 2nd row : ";
break;
case 3:
cout << "Please enter numbers for the 3rd row : ";
break;
default:
cout << "Please enter numbers for the " << curRow << "th row : ";
break;
}
for (int arrayPos=0; arrayPos < columns; arrayPos++)
{
cin >> multiarray[curRow][arrayPos];
}
}
CalcMax();
}
void CalcMax()
{
}
};
int main ()
{
Calculator calc;
calc.GetData();
return 0;
}
|
I won't even start with the errors that I get when trying to pass the vector, but here are the errors I get when trying to declare the vector: (and yes, I have tried googl'ing and finding the answers, but most of them are way over my head)
error: 'std::vector<int>' is not a template
error: expected primary-expression before 'columns'
It's ok to rip this apart. I know I have to start somewhere, but any way you can help would be great.
Thanks!