PLEASE ! Need help fixing my program
I have an assignment where I have to create a program that counts the number of Gs and Cs, G and C together and the total number of characters in the string.
Additionally, there's the requirement to allow input in lower or uppercase, find percentage of g and c and making sure the characters are A,G,C,T. However I haven't gotten to that yet.
I was able to successfully compile the program and run it but it gives the wrong answer. I'm extremely new to C++ and programming, so I don't know what to do. Please help me.
Here's what I have.
Code:
#include <iostream>
#include <string>
using namespace std;
int main () {
string input;
cout << "Please enter Nucleotide sequence:";
getline (cin, input);
int numofChars = input.length();
int numofg = 0;
int numofc = 0;
int numofgc = 0;
for (unsigned int i = 0; i< input.length(); i++) {
if (input.at(i) == 'g' ) {
numofg ++ ;
}
for (unsigned int i = 0; i<input.length(); i++) {
if (input.at(i) == 'c') {
numofc ++;
}
for (unsigned int i = 0; i< input.length(); i++) {
if (input.at(i) == 'g' ) {
if (input.at(i+1) == 'c' ) {
numofgc ++;
}
}
}
cout << " The number of Gs are " << numofg << endl ;
cout << " The number of Cs are " << numofc << endl ;
cout << "The number of GCp are " << numofgc << endl ;
cout << "The total number of characters are " << numofChars ;
}
return 0;
}
}