help with code and error msg plz

K

kittykat

Basically, what I am trying to do is the user is required to enter a
"pattern" which is a combination of the following letters: a, c, t, g. so,
for example, the user can enter agt, or acc, or tgc...and so on.

for now, im assiuming that the user will ONLY enter a combination of these
four letters. When they do, then:

If letter = a, go to first vector.
If letter = c, go to second vector.
If letter = g, go to third vector
If letter = t, go to fourth vector.

Enter 1 for the position in the order that the user enters the pattern.
For example, if the user enters the letters tcg…then this is how it will
be stored in a vector of vectors. assume each row is a vector: (the
numbers at the top are the positions of the elements)

0 1 2
0 0 0
0 1 0
0 0 1
1 0 0

am i making sense?? I hope so.

Ok…so here is my code which I *think* does what I explained above.

#include< ... >
using namespace std;

typedef vector<int> row;

int main()
{
vector<char> DNApattern;
string codon;

cout << "Enter pattern: " << endl;
getline(cin, codon,'\n');

for ( int i=0; i < codon.length(); ++i)
{
DNApattern.push_back(codon);
}

//Testing output for DNApattern Vector
for ( int i = 0; i < DNApattern.size(); i++ )
{
cout << "Letter at position " << i << " is " << DNApattern <<
endl;
}

unsigned int position = codon.length();
row initialisedRow(position, 0);

unsigned int numRows = 4;
vector<row> Data (numRows, initialisedRow);

for (int idx = 0; idx < codon.length(); ++idx)
{
int letterNum = 0;
row& currentRow = Data[letterNum];
int& currentValue = row[idx];
currentValue = currentValue + 1;
}

system("PAUSE");
return 0;
}


My questions:
1) How shall I fix the following error message which says
“primary-expression expected before ‘[‘”, and it is referring to

int& currentValue = row[idx];

2) Is what I’ve written correct?
3) I would also like to know if there is a more efficient or a simpler way
of doing this?
 
H

Howard

kittykat said:
typedef vector<int> row;
int& currentValue = row[idx];
My questions:
1) How shall I fix the following error message which says
primary-expression expected before [, and it is referring to

int& currentValue = row[idx];

In your code, row is a type. But you're treating it as a variable. You
need to specify an actual instance of (or reference to) a row object. I
assume you meant currentRow[idx]?

-Howard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top