diff --git a/CashWorld.cpp b/CashWorld.cpp index 2d37d63..57f2496 100644 Binary files a/CashWorld.cpp and b/CashWorld.cpp differ diff --git a/ui_helper.cpp b/ui_helper.cpp new file mode 100644 index 0000000..a5358e3 --- /dev/null +++ b/ui_helper.cpp @@ -0,0 +1,40 @@ +#include "ui_helper.h" +#include +#include +#include + +void ClearScreen() +{ + system("cls"); +} + +void ClearInput() +{ + int c; + while ((c = getchar()) != '\n' && c != EOF); +} + +void WaitPause() +{ + system("pause"); +} + +void title(const std::string& xtitle) +{ + ClearScreen(); + printf("==============================\n"); + printf("%s\n", xtitle.c_str()); + printf("==============================\n"); +} + +int GetChoice(int max_id) +{ + int x; + while (scanf("%d", &x) != 1 || x<1 || x>max_id) + { + printf("输入有误. 应为在1~%d范围内的数字. 请重试.\n", max_id); + ClearInput(); + } + ClearInput(); + return x; +} \ No newline at end of file diff --git a/ui_helper.h b/ui_helper.h new file mode 100644 index 0000000..fb6703f --- /dev/null +++ b/ui_helper.h @@ -0,0 +1,11 @@ +#pragma once +#include + +void ClearScreen(); +void ClearInput(); + +void WaitPause(); + +void title(const std::string& xtitle); + +int GetChoice(int max_id); \ No newline at end of file