Question:
i need help making corrections to my C++ program?
jayteemoney
2012-09-03 17:57:08 UTC
I am writing a bioinformatics program with a switch statement that has 1 error at the beginning of the statement
error says transfer of control bypasses initialization

my for loop has an error stating
expression must have class type

and finally my if statements say
operands are incompatible (char* and char)

can somebody please help?????
here's my code:

#include
#include
using namespace std;
void Input();
int main()
{
Input();
char A,G,C,T,U;
int input;
int seq;
int complement;
cout<<" Choose your form of input "< cout<<"1=From-File***2=From-Keyboard"< cin>>input;

//error says transfer of control bypasses initialization
switch (input){
case 1:
char transcription[100];
ifstream sequence;
cin.getline(transcription, 100);
sequence.open(transcription);

if(!sequence.is_open()){
exit(EXIT_FAILURE);
}

char transcription2[100];
sequence>>transcription2;
while(sequence.good()){
cout<
//I might take out this for loop because I dont think I need it
//error here says expresion (transcription2) must have class type
for(int i=0; i<=transcription2.length(); i++){
//theres in error in all my if statements under the( == )sign saying
//operands are incompatible (char* and char)
if(transcription2 =='A'){
cout<<"U";
}
if(transcription2 =='G'){
cout<<"C";
}
if(transcription2 =='C'){
cout<<"G";
}
if(transcription2 =='T'){
cout<<"A";
}
else
{
cout<<"there was an error"< }
sequence>>transcription2;
}
}
break;
case 2:
cout<<"Please enter your sequence: ";
cin>>seq;
cout<<"You Enterd: "< cout<<"The complement is: "< if(seq=='A'){
cout<<"U";
}
if(seq=='G'){
cout<<"C";
}
if(seq=='C'){
cout<<"G";
}
if(seq=='T'){
cout<<"A";
}
else{
cout<<"Thats an invalid entry"< }

default:
cout<<"That is an invalid option"< system("PAUSE");
return 0;
}
}
Three answers:
John
2012-09-03 18:12:17 UTC
I do not know which version of C++ you are using, and I am not that familiar with the more recent revisions to the C++ standard. However:



'A' is a character, while transcription2 is an array of characters. You can not compare the two using the '==' operator.



use "A" instead of 'A', "G" instead of 'G', etc etc.

and use strncmp() instead of the '==' operator. I do not know about today, but several years ago, the '==' operator would try to compare the addresses of arrays, rather than the contents of the arrays.



Also, I believe that C++ arrays are pointers, not objects. transcription2 does not have any members which can be accessed with the dot operator. Instead of using transcription2.length(), just use the number 100. Or better yet, define a constant to use as the array's length and use that.
Anas Imtiaz
2012-09-03 19:33:33 UTC
1- You need to include the library to use the length() function.

For more info: http://www.cplusplus.com/reference/string/string/length/



2- You are comparing an entire array with a character i.e. transcription2 == 'A' where transcription2 is an array of 100 characters. If you want to compare an individual element of the array, you have to specify the index first. e.g. if(transcription2[40] = 'A') in this case, the program will compare the 41th character in the array with 'A'
?
2016-12-11 08:54:51 UTC
a million) TAX could desire to be a million.0825 (because of fact you may desire to pay the cost as nicely to the tax). or you're able to do: TotalCost=SubTotal + SubTotal * TAX; 2) You forgot to multiply each and each value by utilising the form of instruments. 3) do away with the 'gadget("pause");' on the tip. this is been out of date for 8 years or so now.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...