Hey guys, I know this code might be a mess and it's definitely not done, but i'm not asking for help with the entire thing. I just need to figure out why I keep getting this stupid error...
Comparison between pointer and integer ('char*' and int') on lines 26 and 43.
#include<iostream>
#include<cctype>
#include<cmath>
usingnamespace std;
char transcribe(char);
char ans;
int main() {
char nt1[10];
char nt2[10];
bool keep_going = true;
cout << "This program is designed to calculate a sequence identity between two different DNA or RNA sequences." << endl;
do {
cout << "Please start by entering the first DNA or RNA sequence. Note: sequence must be exactly 10 characters." << endl;
cin >> nt1;
keep_going = false;
for (int i = 0; i < 10; ++i) {
nt1[i] = transcribe(nt1[i]);
if (nt1 != 'a' && nt1 !- 'A' && nt1 != 'g' && nt1 != 'G' && nt1 != 'c' && nt1 != 'C' && nt1 != 'u' && nt1 != 'U'){
cout << "invalid character was encountered, try again" << endl;
keep_going = true;
break;
}
}
if (keep_going)
continue;
for (int i = 0; i < 10; ++i) {
nt2[i] = transcribe(nt2[i]);
cout << "Please continue by entering the second DNA or RNA sequence. Note: sequence must be exactly 10 characters." << endl;
cin >> nt2;
if (nt2 != 'a' && nt2 !- 'A' && nt2 != 'g' && nt2 != 'G' && nt2 != 'c' && nt2 != 'C' && nt2 != 'u' && nt2 != 'U') {
cout << "invalid character was encountered, start over" << endl;
keep_going = true;
break;
}
}
if (keep_going)
continue;
int counter = 0;
for (int i = 0; i < 10; ++i) {
cout << nt1[i];
if (nt1[i] == nt2[i]) {
++counter;
}
}
cout << counter;
cout << " over 10" << endl;
// nt1 and nt2
cout << "Did you want to run the program again?\n Please type 'y' to test another sequence or press any other key to quit.";
cin >> ans;
}
while (ans != 'Y' || ans != 'y');
return 0;
}
char transcribe(char nt){
if (nt == 't' || nt == 'T')
return'U';
elsereturn toupper (nt);
}
Line 26,43: nt1 is an array of chars. You're trying to compare a character literal to an array. That's not supported. You want to compare a specific character from the array to the character literal.
Line 26,43: Since transcribe() does an upshift, there is no reason to check lower case charaters here.
Line 26,43: You have a typo. nt1 !- 'A' should be nt1 != 'A'
Line 37-38: You're trying to call transcribe() on nt2, but nt2 has not been input yet.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thank you, sorry about the code tag. It should be fixed now.
I still am a little confused, though. Where are you talking about I should use double quotes? I thought you had to use single quotes inside the if statements?
Line 26,43: nt1 is an array of chars. You're trying to compare a character literal to an array. That's not supported. You want to compare a specific character from the array to the character literal.
#include <iostream>
#include <cctype>
#include <cmath>
usingnamespace std;
void transcribe(char *); // Changed to operate on array
// Return true if all characters in sequence are value
bool is_valid (constchar * nt)
{ for (int i=0; i<10; i++)
{ // Changed to use index and eliminate lower case compare
if (nt[i] != 'A' && nt[i] != 'G' && nt[i] != 'C' && nt[i] == 'U')
{ cout << "invalid character was encountered, try again" << endl;
returnfalse;
}
}
returntrue;
}
int main()
{ char nt1[10];
char nt2[10];
bool keep_going = true;
char ans; // moved from globals
cout << "This program is designed to calculate a sequence identity between two different DNA or RNA sequences." << endl;
do
{ cout << "Please start by entering the first DNA or RNA sequence. Note: sequence must be exactly 10 characters." << endl;
cin >> nt1;
transcribe (nt1);
keep_going = false;
if (! is_valid (nt1))
{ keep_going = true;
break;
}
if (keep_going)
continue;
cout << "Please continue by entering the second DNA or RNA sequence. Note: sequence must be exactly 10 characters." << endl;
cin >> nt2;
transcribe(nt2);
if (! is_valid (nt2))
{ keep_going = true;
break;
}
if (keep_going)
continue;
int counter = 0;
for (int i = 0; i < 10; ++i)
{ if (nt1[i] == nt2[i])
++counter;
}
cout << endl;
if (counter == 10)
cout << "Sequences are the same" << endl;
else
cout << "Sequences are not the same" << endl;
// nt1 and nt2
cout << "Did you want to run the program again?\n Please type 'y' to test another sequence or press any other key to quit.";
cin >> ans;
}
while (ans != 'Y' || ans != 'y');
return 0;
}
// Change to operate on sequence
void transcribe (char * nt)
{ for (int i=0; i<10; i++)
if (nt[i] == 't' || nt[i] == 'T')
nt[i] = 'U';
else
nt[i] = toupper (nt[i]);
}