You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <stdio.h>
# include <time.h>
# include <stdlib.h>
int main ( ) {
int choice ;
printf ( " 欢迎使用学生考试系统 \n " ) ;
char name [ 100 ] ;
char xuehao [ 110 ] ;
//设置两个储存姓名和学号的字符串数组
printf ( " 请选择系统功能选项: 1: 登入 0: 退出 \n " ) ;
//模拟正式考试系统时的考试界面
scanf ( " %d " , & choice ) ;
switch ( choice )
{
case 1 : printf ( " 请输入你的姓名、学号 \n " ) ;
scanf ( " %s " , name ) ;
scanf ( " %s " , xuehao ) ;
printf ( " 请开始答题: \n " ) ;
//使用字符串数组输入姓名和学号
int a , b , c , i , j , score [ 10 ] , trueValue , sum = 0 ;
srand ( time ( NULL ) ) ;
for ( i = 0 ; i < 10 ; i + + ) {
for ( a = rand ( ) % 51 , b = rand ( ) % 51 ; a + b > 50 | | a + b < 0 | | a - b > 50 | | a - b < 0 ; a = rand ( ) % 51 , b = rand ( ) % 51 )
c = rand ( ) % 2 ;
//使用rang函数随机生成[0, 50]以内的数字
//c随机生成0和1, 分别对应加法和减法
for ( j = 0 ; j < 3 ; j + + ) {
if ( c = = 1 ) {
printf ( " %d:%d+%d= " , i + 1 , a , b ) ;
trueValue = a + b ;
//加法公式
scanf ( " %d " , & score [ i ] ) ;
if ( score [ i ] ! = trueValue ) {
printf ( " 答案错误,请重新输入. \n " ) ;
score [ i ] = 0 ;
}
else {
if ( j = = 0 ) {
score [ i ] = 10 ;
}
else if ( j = = 1 ) {
score [ i ] = 7 ;
}
else {
score [ i ] = 5 ;
}
break ;
}
}
//加法的计分方式
else {
printf ( " %d:%d-%d= " , i + 1 , a , b ) ;
trueValue = a - b ;
//减法的公式
scanf ( " %d " , & score [ i ] ) ;
if ( score [ i ] ! = trueValue ) {
printf ( " 答案错误,请重新输入. \n " ) ;
score [ i ] = 0 ;
}
else {
if ( j = = 0 ) {
score [ i ] = 10 ;
}
else if ( j = = 1 ) {
score [ i ] = 7 ;
}
else {
score [ i ] = 5 ;
}
break ;
}
}
}
if ( score [ i ] = = 0 ) {
printf ( " 正确答案是:%d \n " , trueValue ) ;
}
//减法的计分方式
sum = sum + score [ i ] ;
}
printf ( " 你的成绩是:%d \n " , sum ) ;
if ( sum > 90 ) {
printf ( " SMART. \n " ) ;
}
else if ( sum > = 80 ) {
printf ( " GOOD. \n " ) ;
}
else if ( sum > = 70 ) {
printf ( " OK. \n " ) ;
}
else if ( sum > = 60 ) {
printf ( " PASS. \n " ) ;
}
else {
printf ( " TRYAGAIN \n " ) ;
}
break ;
case 0 : break ; }
return 0 ;
}