Sarika73
January 18th, 2003, 02:06 AM
Hi
I am a beginner in C++. I am trying towrite a program where the user enters the number of sequences which can be more than 1 and then compare each letter of the sequence with each element of char array.but it falls over on line 80.
Any help is appreciated.
------------------------------------------------------------------------------
// This program asks the user to enter the no of sequences
// and read the sequences as string and then compare them
// Assumption
// The char of sequences should be A,C,T,G,U
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool checkSequenceChar(string);
int main()
{
int input = 0; // sequence
vector<string> sequences;
cout << "Enter The Number Of Sequence in PTree: ";
while(!(cin >> input))
{
string buffer;
cin.clear(); //clear failbit
cin >> buffer; //flush stream
cout << "Invalid Input.. Please Enter An Interger Only !!!" << endl;
cout << "Enter The Number Of Sequence : ";
}
for (int i = 0; i < input; i++)
{
string temp;
// store the elements in array.
cout << "Please Enter Sequence [" << i << "] : " ;
cin >> temp;
sequences.push_back(temp);
}
for (int i = 0; i < input; i++)
{
for (int j = 0; j < sequences[i].length(); j++)
{
string seqChar;
seqChar = sequences[i].substr(j,1);
if ( checkSequenceChar(seqChar) )
{
cout << "Sequence [" << i << "] Matches " << sequences[i] <<endl;
}
else
{
cout << "Sequence Doesn't [" << i << "] Matches " << sequences[i] <<endl;
}
}
}
return 0;
}
// checks every char of the sequence entered
bool checkSequenceChar(string c)
{
char seqFilter[] = "ACTGU";
cout << " The Comparision Char is : " << c << endl;
for (int i = 0; i < 5; i++)
{
cout << "Sequence Pick : " << " " << i << " " << seqFilter[1] << endl;
// THE PROGRAM FALLS HERE
if ( seqFilter[i] != c )
{
cout << "Sequence Char NOT Matches : " << c << " " << seqFilter[i] << endl;
//return false;
}
}
return true;
}
I am a beginner in C++. I am trying towrite a program where the user enters the number of sequences which can be more than 1 and then compare each letter of the sequence with each element of char array.but it falls over on line 80.
Any help is appreciated.
------------------------------------------------------------------------------
// This program asks the user to enter the no of sequences
// and read the sequences as string and then compare them
// Assumption
// The char of sequences should be A,C,T,G,U
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool checkSequenceChar(string);
int main()
{
int input = 0; // sequence
vector<string> sequences;
cout << "Enter The Number Of Sequence in PTree: ";
while(!(cin >> input))
{
string buffer;
cin.clear(); //clear failbit
cin >> buffer; //flush stream
cout << "Invalid Input.. Please Enter An Interger Only !!!" << endl;
cout << "Enter The Number Of Sequence : ";
}
for (int i = 0; i < input; i++)
{
string temp;
// store the elements in array.
cout << "Please Enter Sequence [" << i << "] : " ;
cin >> temp;
sequences.push_back(temp);
}
for (int i = 0; i < input; i++)
{
for (int j = 0; j < sequences[i].length(); j++)
{
string seqChar;
seqChar = sequences[i].substr(j,1);
if ( checkSequenceChar(seqChar) )
{
cout << "Sequence [" << i << "] Matches " << sequences[i] <<endl;
}
else
{
cout << "Sequence Doesn't [" << i << "] Matches " << sequences[i] <<endl;
}
}
}
return 0;
}
// checks every char of the sequence entered
bool checkSequenceChar(string c)
{
char seqFilter[] = "ACTGU";
cout << " The Comparision Char is : " << c << endl;
for (int i = 0; i < 5; i++)
{
cout << "Sequence Pick : " << " " << i << " " << seqFilter[1] << endl;
// THE PROGRAM FALLS HERE
if ( seqFilter[i] != c )
{
cout << "Sequence Char NOT Matches : " << c << " " << seqFilter[i] << endl;
//return false;
}
}
return true;
}