hi everyone,

i am working on a simple C++ code that will randomly generate a DNA strand of bases. How this is what i have so far:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
string my_string;

int main()
{
 int random_integer;
 char 1 = 'A';
 char 2 = 'T';
 char 3 = 'C';
 char 4 = 'G';
 cout << "Length of DNA to be generated is 20 bases." << endl;
 {
     srand((unsigned)time(0));
     int lowest=1, highest=4;
     int range=(highest-lowest)+1;
     for(int index=0; index<20; index++)
     {
         random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
         cout << random_integer << endl;
     }
 }
 {
  cout<< "Now after every A there will be a C insertion (mutation)"<< endl;
  string my_string = "A";
  my_string.insert (1,"C");
 }
 {
  cout<< "Now after every G there will be a T insertion (mutation)"<< endl;
  string my_string = "G";
  my_string. insert  (1, "T");
 }

return 0;
}

my problems are this:

1) when i try to compile (using borland) it keeps telling me declaration terminated incorrectly on line 9 and i cant figure out a way to fix it
2) is there a way to get it so you can imput how many bases the random genertor generates??


that is it... i hope someone can help me... I NEED IT QUICKLY!!!!!:mrgreen: Thank you so much in advance

First of all, your title violates our rules. Please Read This

In the code

char 1 = 'A';
char 2 = 'T';
char 3 = 'C';
char 4 = 'G';

where are the variable names? Variables cannot start with a number. What you are trying to do is change the value of the number 1. Ain't gonna work.

first let me apoligize for the title of the post... i was unaware of that rule but i do apoligize.


is there anyway in C++ to change numbers that are generated by the random number generator to letters?? i search through my text book and on websites and cant seem to find anything

first let me apoligize for the title of the post... i was unaware of that rule but i do apoligize.

Not a big problem. Just annoying when it happens a lot. Title of the post is best when it gives us an idea what the question is about.

is there anyway in C++ to change numbers that are generated by the random number generator to letters?? i search through my text book and on websites and cant seem to find anything

You don't change the numbers, you use the numbers as
1) an index into an array of letters
2) as a base to calculate the 'value' of a letter

I still have no idea what exactly you are asking, but assuming it's number one and you want 1 == 'A', 2 = 'T', etc, you can create an array char letters[4] = 'A','T','C','G'; Now you can get a random value from 0-3 random_integer = rand() % 4; Now, your letter is letters[random_integer]; If this is not what you are trying to do, please explain.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.