noble3ad 24 Newbie Poster

Hello,

I'm in an introductory computer programming course and I'm very new. I've been trying to write a program that will allow a user up to five tries to guess a randomly generated number. Here is what I have so far:

#include <stdio.h> //enables printf and scanf functions
#include <stdlib.h> //enables random number function

int main()
{
	//LOCAL DECLARATION SECTION.
	int random_number;
	int guess;

	//Setting the seed to generate a random number
	srand (313);

	//Getting the random number.
	random_number = rand () % ((20 - 1 + 1) + 1);

	[B]printf("\n\nPlease guess the number between 1 and 20: ");
	scanf("%d", &guess);
	
	
	if (guess != random_number)
	{
		printf("Sorry.  You have guessed the wrong number.");
		
	}
	 
		if (guess > random_number)
		{
			printf("\nYour guess is greater than the number.  Try again.");
		}
		else if (guess < random_number)
		{
			printf("\nYour guess is lower than the number.  Try again.");
		}

		else if (guess = random_number)
		{
			printf("\nCONGRATULATIONS!  You have guessed the correct number.");
		}[/B]

It's works fine so far but I don't know how to get the program to repeat itself up to five times until the user guesses the right number. The program is suppose to terminate if the user guesses the right number OR has guessed five times. We haven't learned anything about loops so is there a method in which to do this without using loops? The only thing I can think of right now is to copy the part in bold-face five times. However, it'll still continue to ask …

Ancient Dragon commented: Thanks for taking the time to use code tags correctly :) +24