Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************/
- /** 20140519 Classwork_0430 Question 1 Answer **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/05/19 am.01:19 **/
- /***********************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int process_input(int, int);
- void exit_program();
- void main()
- {
- srand(time(NULL));
- int random = rand() % (100 - 1 + 1) + 1;
- while(1)
- {
- printf("Please guess a number: ");
- int input = 0;
- scanf("%d", &input);
- if(input == 0)
- {
- exit_program();
- }
- else if(input > 0)
- {
- switch(process_input(input, random))
- {
- case 0:
- printf("My answer is smaller than %d.\n", input);
- break;
- case 1:
- printf("My answer is larger than %d.\n", input);
- break;
- case 2:
- printf("Bingo!! You got it!!\n\n");
- exit_program();
- break;
- }
- }
- }
- }
- int process_input(int input, int random)
- {
- if(input > random)
- {
- return 0;
- }
- else if(input < random)
- {
- return 1;
- }
- else if(input == random)
- {
- return 2;
- }
- }
- void exit_program()
- {
- printf("You are exiting now ..\n");
- exit(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment