回复 9楼 azzbcc
可是当时14也错了
问题还是那几个,不能用 = 做判断
printf ("%d/%d=",a, b!=0); 不对,应该是 printf("%d / %d = ", a, b);
if (ans =a/b) 也不对,应该用 if (ans * b == a)
#define _CRT_SECURE_NO_WARNINGS #include <time.h> #include <stdio.h> #include <stdlib.h> int Add() { int ans; int a = rand() % 100; int b = rand() % 100; printf("%d + %d = ", a, b); scanf("%d", &ans); getchar(); return a + b == ans; } int Sub() { int ans; int a = rand() % 100; int b = rand() % 100; printf("%d - %d = ", a, b); scanf("%d", &ans); getchar(); return a - b == ans; } int Mul() { int ans; int a = rand() % 100; int b = rand() % 100; printf("%d * %d = ", a, b); scanf("%d", &ans); getchar(); return a * b == ans; } int Div() { int ans; int a = rand() % 100; int b = rand() % 10 + 1; a = a / b * b; printf("%d / %d = ", a, b); scanf("%d", &ans); getchar(); return a == b * ans; } int main(void) { int ch, questions = 0, rights = 0; srand(time(NULL)); do { questions += 1; switch (rand() % 4) { case 0: if (Add()) { rights += 1, puts("RIGHT!"); } else { puts("ERROR!"); } break; case 1: if (Sub()) { rights += 1, puts("RIGHT!"); } else { puts("ERROR!"); } break; case 2: if (Mul()) { rights += 1, puts("RIGHT!"); } else { puts("ERROR!"); } break; case 3: if (Div()) { rights += 1, puts("RIGHT!"); } else { puts("ERROR!"); } break; default:break; } printf("\n继续(Y) OR 结束(N)[Y]:"); ch = getchar(); if ('\n' == ch) { ch = 'Y'; } else { getchar(); } } while ('Y' == ch || 'y' == ch); printf("%.2f%%\n", rights * 100.0 / questions); return 0; }