Posts for bubsy

Joined: 2/14/2009
Posts: 1
Location: Norway
#include <stdio>
#include <stdlib>
#include <conio>
#include <time>

#define maxNumber 100
#define maxGuess 10

void seedNum(int n1, int n2);

int main() 
{
	int n1, n2, answer;
	seedNum(n1, n2);
	
	int numGuess = 0;
	while (numGuess != maxGuess)
	{
		printf("Add these two numbers together: %d and %d\n", n1, n2); 
		scanf("%d", &answer); 

		if (answer == (n1 + n2))
		{
			printf("Correct! Now follows a new one...\n");
			seedNum(n1, n2);
			numGuess = 0;
		}
		else
		{
			printf("Sorry, that's incorrect.\n");
			numGuess++;
		}
	}
	printf("Game Over.\n");

	// send any awaiting chars in input buffer and wait for a key press...
	fflush(stdout);
	getch();

	return 0; 
}

void seedNum(int n1, int n2)
{
	srand(time(0)); 
	n1 = 1 + rand() % maxNumber;
	n2 = 1 + rand() % maxNumber;
}

Or something like that, I haven't tested it. Somehow .h is automatically removed from the includes.