need help making corrections to my bioinformatics program

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:
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
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 "<<endl;
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<<transcription2<<" "<<endl;

//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"<<endl;
}
sequence>>transcription2;
}
}
break;
case 2:
cout<<"Please enter your sequence: ";
cin>>seq;
cout<<"You Enterd: "<<seq;
cout<<"The complement is: "<<endl;
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"<<endl;
}

default:
cout<<"That is an invalid option"<<endl;
system("PAUSE");
return 0;
}
}
closed account (o3hC5Di1)
Hi there,

28
29
30
31
32
33
34
35
36
37
38
39
char transcription2[100];
sequence>>transcription2;
while(sequence.good()){
cout<<transcription2<<" "<<endl;
//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";
}


You initialise transcription2 as an array, so you cannot do transcriptions2.length() - char arrays are not a class of which you can call the .length() member function.

You will either have to use strlen() (note that you will have to include another header file for this) or you will need to redefine your loop to do i < 100 //transcription2 max size is 100 and within the loop check if (transcription2[i] = '\0') break // if end of string, break from loop .

As for the operands error, you are checking the name of the array against a character constant. Array names are basically pointers (char*) to the first character of the array (/ string). In order to check an individual character to a character constant you would do if( transcription2[i] = 'A') where i is your for-loop counter variable.

The error you get on the switch statement possibly occurs because there are errors within the switch statement, so if you resolve these two that could well be resolved too.

Hope that helps.

All the best,
NwN

Topic archived. No new replies allowed.