why the result is always the same?

#include<iostream.h>
#include<conio.h>
#include<time.h>
#include<dos.h>
#include<stdlib.h>
int main()
{
int a,b,c;
clrscr();
a = 5; b = 5; c = 5;
for(int x=1; x<=24; x++)
{
gotoxy(5,x);
cout << "*";
gotoxy(70,x);
cout << "*";
delay(50);
}
clrscr();
do
{
for(int x=1; x<=24; x++)
{
gotoxy(5,x);
cout << "*";
gotoxy(70,x);
cout << "*";
}
gotoxy(a,5);
cout << "A";
gotoxy(b,10);
cout << "B";
gotoxy(c,15);
cout << "C";
a = a + rand()%5+1;
b = b + rand()%5+1;
c = c + rand()%5+1;
delay(50);
}
while(a<=70 || b<=70 || c<=70);
getch();
return 0;
}

The rand() function will repeat the very same numbers, in every run, unless you seed the random number generator ONE TIME, before you use it.

So

#include <time.h>
#include <stdlib.h>

//then
srand(time(0));
//before any call to rand(),

and you'll be all set.

When you get a chance, you'll be miles ahead if you stick with ONE language. You are using headers from C++, and also from C.

Also, the C++ headers are VERY VERY OLD, and now obsolete. OK, they were obsolete 10 years ago, but who's counting. Turbo C/C++ looks like.

Jump over to a modern compiler and IDE like Pelles C, and you will be impressed. If you want C++ though, go with one of the newer C++ compilers and IDE, like Microsoft Express.

thanks for the reply.. but why it the program won't stop until the 3 variable is already greater than 70?? i just need one like if a is greater than or equal to 70 it will stop ..

i'm new to programming . what language is the best to study??

why it the program won't stop until the 3 variable is already greater than 70??

Because your while condition says the the program should loop while either of the variables is less than 70. Let's say your variables are a=77, b=70, c=67. Is the statement "a is less than 70, b is less than 70, or c is less than 70" true? Yes because c is less than 70 and "false or false or true" is true.

If you want it to stop when either variable is greater than or equal to 70, you need to loop while all of them are less than 70. So you need to replace your ors with ands.

i just need one like if a is greater than or equal to 70 it will stop ..

if you mean the condition at line 40 then it's because if any of the condition remains true then it will continue to loop (if any of the variables is less than or equal to 70)

thanks already solved .. i forgot that i need to use && instead of ||

thanks for the reply

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.