#include <stdio.h> #include <stdlib.h>

int main(){ int score = 0; int difficulty = 0; int round = 0; int answer = 0; int correctAnswer = 0;

printf('Welcome to the game!

'); printf('Please enter the difficulty level (1-3): '); scanf('%d',&difficulty);

while(round < 10){
    correctAnswer = rand() % (difficulty*2)+1;
    printf('Round %d: What is the answer for the equation?

',round+1); printf('%d + %d = ? ',rand() % (difficulty2)+1,rand() % (difficulty2)+1); scanf('%d',&answer); if(answer == correctAnswer){ printf('Correct! '); score += 5; }else{ printf('Incorrect! The correct answer is %d ',correctAnswer); score -= 2; } round++; }

printf('Game over. Your final score is %d

',score);

return 0;

}

C语言嵌入式游戏代码示例 - 简单加法游戏

原文地址: https://www.cveoy.top/t/topic/ljFj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录