For an assignment I am needing to read characters from a text file and they are set up like this: ACTCACGCATCGACGT. I am supposed to read the file, output an error if there is any non-nucleotides and calculate the total number of the nucleotides. Then find the total of each nucleotide A, T, G, and C.
This what I currently have and it is not working for the first part:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream idata;
char ch;
int A=0, T=0, G=0, C=0;
idata.open("dnaSequence.txt");
idata.get(ch);
while(idata)
{
if ( ch =='A')
A++;
else if (ch == 'T')
T++;
else if (ch == 'G')
G++;
else if (ch == 'C')
C++;
}
idata.get (ch);
cout<< ch << endl;
cout<<"A= " << A <<"\nT= " << T << "\nG= " << G << "\nC= " << C <<endl;