Adak 419 Nearly a Posting Virtuoso

On lines 33, 41, 122, etc., you have put two "==" (a test for equality), instead of just one equal sign, (for assignment).

Turn on your warnings on your compiler, and you'll be told all this and more.

Variables x and y are never used in survivalRule(), birthRule(), etc.

Life[][] is an array of char's, so don't print strings. Add a sleep(1) or more, between the display of generations, so you can see what's going on.

What it REALLY needs is a board display that doesn't scroll on the screen. You can do that using the header file <conio.h> with gotoxy(), in Turbo C, or use the Windows API and use Gotoxy(), along with <windows.h> header.

Adak 419 Nearly a Posting Virtuoso

Can anybody help me to solve this problem?
My program doesn't work as what it is required. Here is the question and my program code.
Thanks.

/**Twenty-five numbers are entered from the keyboard into an array. 
Write a program to find out how many of them are positive, 
how many are negative, how many are even and how many odd. **/

#include<stdio.h>

int main()
{ 
int num[5];
int i, even_number, odd_number, positive_number, negative_number;


printf("Enter 5 int numbers ");
for (i=0;i<=4;i++){
scanf("%d",&num[i]);
}
even_number = odd_number = positive_number = negative_number = 0;
for(i=0;i<=4;i++){	
	if(num[i]%2==0){
	//printf("\nEven number : %d",num[i]);
        even_number++;
        }
	else if(num[i]<0){
	//printf("\nNegative number : %d",num[i]);
        negative_number++;
	}
        //like the above, for the last two types of numbers.
	else if(num[i]%2!=0){
	printf("\nOdd number : %d",num[i]);
	}
	else if(num[i]>=0){
	printf("\nPositive number : %d",num[i]);
	}
}

printf("\n There were %d even numbers, %d odd numbers, %d negative numbers, and %d positive numbers", 
even_numbers, odd_numbers, negative_numbers, positive_numbers);

return 0;
}

That should get you off to a good start.

Adak 419 Nearly a Posting Virtuoso

That's not entirely correct I'm afraid.

I only display the board when it is solved, that's also when I calculate the difference in time.

Notice the #ifdef DEBUG in front of the "print the board after every move" line. That line only gets compiled when DEBUG is defined, which it isn't. It was there for, naturally, debugging purposes.

Then you need to start bringing the facts forward, and start including data: How long does your program take to run, and on what hardware?

Have you profiled it yet, and what were the results?

What compiler are you using, and with what flags?

I'm sure you could google around and find other versions of this program. How does your program compare to them, when run on the same hardware and compiler?

That will give you real insight into the performance of your program.

Adak 419 Nearly a Posting Virtuoso

Recalculating the time in every recursive call, get's quite expensive. Perhaps depth mod 8 == 0 would be enough?

Also, you re-draw the board for every move. You only need to redraw two squares after any move - the from square, and the to square. It also gets rid of any possible screen flicker.

Adak 419 Nearly a Posting Virtuoso

May I suggest you use the digits 1, 2 & 3, instead of 0, 1, & 2?

Because you can't "make" a number which begins with 0's: 01, 001, 02, 002, etc., are not a number. Anything beginning with a real number, would be fine though: 101, 20, 103, etc.

Other idea's would include using bit values within the bytes, but that sounds unnecessarily difficult for a beginner, and keeping the values in an integer array, where the zero's would be fine.

Always put your code between code tags on any forum.

Adak 419 Nearly a Posting Virtuoso

Hey friend. I can't find your idea. I don't know how to start in making a status bar. I need to do in the dos console.

Are we talking about the same thing? I'm talking about a little DOS type thingy that might look like this:

|======================================|                                                                                    
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
|======================================|

A very crude representation, but you get the idea, I hope. There is no GUI required for it, the lines are made by printing out ASCII char's (not the primitive one's I've had to do here).

The green color could be any DOS color you like, and the X's would be replaced with ASCII char 185, 186, or 187, which is a full cursor char, with light texture on it.

Back in the DOS days, this was good looking stuff, and Windows still uses a bit of it, today, because it does look quite good.

Adak 419 Nearly a Posting Virtuoso

The -mt option gives me this "warning: No Stack".

I don't believe the borland compiler is buggy, but I do believe you'll need to do some research, perhaps on a website dedicated to borland's legacy compilers, and see what's the right way to do this.

I'm new here. Do you have any old timer's who might remember how this is done with Turbo C, around? :)

Wish I could help you out, but I have never worked with separate compilation, and linking.

Adak 419 Nearly a Posting Virtuoso

Did you try my idea I posted on Cprogramming?

Post up some code! Even if it's wrong, post up some effort you've made, and show us just what you want. There must be 100 different ways to make a status bar.

Adak 419 Nearly a Posting Virtuoso

My version, which has int main, instead of void main, works fine using: "tcc <filename>

And I did notice it! :)

Adak 419 Nearly a Posting Virtuoso

I compiled from the IDE.

If using int main doesn't help correct your program's starting address, can you just set the address, explicitly?

jephthah commented: good spot! +3
Adak 419 Nearly a Posting Virtuoso

I don't have Turbo C 2.0, but this runs fine in Turbo C/C++ ver. 1.01, as a C program. Note int main and the include header.

IIRC Turbo C 2.0 came before Turbo C/C++, but it's been a long time.

#include <stdio.h>  

void f(char *);

char h[] = "hello";
  
int main() {
   int gar;
   f(h);
   gar = getchar(); gar++;
   return 0; 
}
void f(char *s) {
   int n = 0;
  
   while (s[n] != '\0') {
      /*do something*/
      putchar(s[n++]);
   }
}