偶也来一个
程序代码:
#include <iostream> #include <ctime> const char *subter_ = "少了!", *hyper_ = " 高了!", *right = "恭喜你猜对了!"; const char* get_diff(int input, int random){ return (input > random) ? hyper_ : ((input < random) ? subter_ : right); } int judge(int input, int random){ return puts(get_diff(input, random)),(input == random) ? 1 : 0; } int main(void){ srand((unsigned)time(0)); long random = rand() % 1000 + 1, init_money = 0, input = 0, degree = 11; while(degree--) (scanf("%d", &input),(!judge(input, random)))? judge(input, random),printf("你还有%d次机会\n", degree) : 1; return 0; }