Hi everyone,
I'm looking for some advice on how to go about my program (not looking for you to do my homework!).
I have to write a program that gives a user two choices for a game or to exit.
The two games, are a dice game(guessing the role of two dice), and the second is guessing a number between 1 and 100.
I have written both games separately and they both work. However, I am having trouble putting them together in a single program, because the games' functions need to be called, and not just in the regular main function.
Here is my code for the guessing game:
Code:
:
#include<stdio.h>#include<stdlib.h>
void main()
{
int random_number, user_input;
random_number=rand() %100+1;
int counter=0;
printf("Welcome to the number guessing game!\n");
do
{
printf("Guess the random number between 1 and 100:\n");
scanf("%d",&user_input);
if (user_input == random_number){
printf("That is the random number!\n");
}
else if (user_input > random_number){
printf("Your guess is too high.\n");
}
else if(user_input < random_number){
printf("Your guess is too low.\n");
}
counter++;
}while (random_number!=user_input);
printf("\nCongratulations! It took you %d tries", counter);
return 0;
}
So is there a way to take all the above code, and call it say "function_guess" and just put it at the top of my program, then when I need to call it I put "function_guess ()", and then it executes the code?
Thanks for your time, I hope I am not being too confusing.
-cda67