Tuesday, July 28, 2009

Can anyone help me how to do this program??

i would like to make a rat race program using c++ language and using the borland compiler.=)...could anyone pls help me do this. my idea is to represent 10 rats with the " } " symbol. and the finish line of the rat is in column 70. the only wat that the a rat could win is that the computer chooses a random number that is ranging from 1-10... the sample output is this :





1. } +


2. } +


3. } +


4. } +


5. } +


note : the addition sign is to denote the finish line..


...i hav the idea but i could not write it in a c++ language...=(..


so pls guys, help this poor girl in need...PLEAASSSEEEE

Can anyone help me how to do this program??
I don't have the time to completely answer your question -- and specifically, I don't know what features of C++ you wish to use (classes, stl, templates). So, my solution is C, using POSIX libraries (and should work just fine with *any* C++ or C compiler -- assuming that it is standards compliant).


Caveat emptor - I don't have the time to compile or test this solution.





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





#define N_RATS 10


#define COURSE 72





int rats[N_RATS] = { 0 };





int main(void)


{


printf("And they're off!\n");


for (;;) {


int r, i, j;


/* See Numerical Recipes in C, 2nd ed, pp 277 */


r = 1 + (int) ((double)N_RATS * (rand() / (RAND_MAX + 1.0)));


if (++rats[r] %26gt;= COURSE) {


printf("And rat %d wins!\n", r);


return 0;


}


/* print race */


for (i = 0; i %26lt; N_RATS; ++i) {


printf("[%2d] ", i);


for (j = 0; j %26lt; rats[i]; ++j) printf("=");


printf("}\n");


}


}


return 0;


}
Reply:Talk to me at NolesToGiants@gmail.com





Drop me an email with the assignment and requirements.
Reply:well, maybe you could write the idea first in the question, then ill try to write the algorithm or function. :D
Reply:You do seem to ask a lot of questions on this forum that each give the impression they are homework assignments... You hide the fact (that they are homework assignments) well, though!





Hey, here's an idea... Why do you go back to the other questions you've asked, and select a best answer? People have gone through the effort of helping you, why don't you go through the effort of rewarding them?


No comments:

Post a Comment