How do I compare two characters and give it a value?

Hi guys,

I just found out I can't use arrays or strings for my homework assignment so I have to redo the entire thing.

I have most of it done, however, I can't figure out how to give a value to two compared characters. Here is a short section of what I'm having trouble with

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
#include<iostream>
#include<cctype>
#include<cmath>

using namespace std;
char transcribe(char);
char nta;
char ntk;
double ntak;

int main() {
    
    cout << "This program is designed to calculate a sequence identity between two different DNA or RNA proteins." << endl;

    while (true)
    {
    cout << "Please start by entering the first nucleotide of the first DNA or RNA sequence." << endl;
    cin >> nta;
        nta = transcribe(nta);
        if (nta != 'A' && nta != 'G' && nta != 'C' && nta != 'U' )
            cout << "You did not input a correct nucleotide. Please try again." << endl;
         else
             break;
        }
while (true)
    {
        cout << "Please start by entering the first nucleotide of the second DNA or RNA sequence." << endl;
        cin >> ntk;
        ntk = transcribe(ntk);
        if (ntk != 'A' && ntk != 'G' && ntk != 'C' && ntk != 'U' )
            cout << "You did not input a correct nucleotide. Please try again." << endl;
        else
            break;
        }
double ntSequence;
    if (nta == ntk)
        ntak = 1;
    else
        ntak = 0;
    ntSequence = ntak/10;
    cout << ntSequence << endl;
    
    return 0;
    }

char transcribe(char nt){
    if (nt == 't' || nt == 'T')
        return 'U';
    else
        return toupper (nt);
}


So theoretically, my ntSequence value should be 0.1 or 0 if nta == ntk or nta != ntk, respectively. However, nothing is outputted. I can't figure out the math formula part on why it's not working. The rest works just fine.

Edit: SOLVED: I'm an idiot..I didn't mark my variable as double! Crisis averted! Sorry guys!
Last edited on
On lines 36, 38 and 39 - did you mean ntk? There is no variable named ntak.
Crap sorry, forgot to add that. Just added it now.

ntak should be its own variable. The value of ntak should be either 1 or 0 depending on if nta and ntk are equal or not. So total of three variables.
Last edited on
Topic archived. No new replies allowed.