-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsortify.c
62 lines (53 loc) · 1.58 KB
/
sortify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MSG_WELCOME "WELCOME TO SORTIFY!"
#define MSG_SORT "Sort the following numbers:"
#define MSG_SORT2 "Please sort the numbers"
#define MSG_WELL "Well done!"
#define MSG_WIN "Congratulations, you win!"
#define MSG_OVER "Game Over."
#define MSG_WRONG "Wrong answer."
#define MSG_MAX "You have reached the maximum number of moves."
#define MSG_BYE "Bye."
#define MSG_UNKNOWN "Unknown option."
/* Use puts() to print constant strings */
int rand_number(const int, const int);
void print_status(const int, const int, const int);
void print_menu(void);
int main(int argc, char **argv)
{
puts(MSG_WELCOME);
return 0;
}
/* generate a random integer between min and max */
int rand_number(const int min, const int max)
{
if (max < min)
{
puts("Max must be larger than Min");
exit(0);
}
int n = abs(max - min) + 1;
return (rand() % n) + min;
}
/* print the game status */
void print_status(const int level, const int score, const int plays)
{
puts("+-----------------------------+");
printf("| level: %02d |\n", level);
printf("| points: %02d |\n", score);
printf("| plays: %02d |\n", plays);
puts("+-----------------------------+");
}
/* print the option menu */
void print_menu(void)
{
puts("+-----------------------------+");
puts("| SORTIFY |");
puts("| p - next chalenge |");
puts("| q - quit |");
puts("| m - print this information |");
puts("| s - show your status |");
puts("+-----------------------------+");
}