--- capa/capa51/pProj/capaCommon.c 2001/01/29 23:25:22 1.19 +++ capa/capa51/pProj/capaCommon.c 2004/03/26 20:02:03 1.23 @@ -2499,7 +2499,7 @@ char *buf;double *num; char *num_p; char while( isspace(buf[idx]) ) { idx++; } sscanf(num_str, "%lg", &result); /* put the numerical value into a double variable */ errcode = errcode | 1; - } else if( buf[idx] == 'x' || buf[idx] == 'X') { /* optional x or X part */ + } else if( buf[idx] == 'x' || buf[idx] == 'X' || buf[idx] == '*') { /* optional x or X part */ idx++; /* skip x or X */ while( isspace(buf[idx]) ) { idx++; } @@ -2897,6 +2897,16 @@ answers_string(mode, p)int mode;Problem_ } +int check_for_unit_fail(int result) +{ + int ret; + ret = (result == UNIT_FAIL || + result == UNIT_IRRECONCIBLE || + result == UNIT_INVALID_STUDENT3 || + result == UNIT_INVALID_STUDENT2 || + result == UNIT_INVALID_STUDENT1); + return ret; +} /* ------------------------------ called from capalogin */ /* impose stronger checking on the user input string *answer */ @@ -2921,7 +2931,7 @@ capa_check_ans(ai,ans, error) AnswerInfo int sig, corr_len; int choice[ANSWER_STRING_LENG]; char num_str[ANSWER_STRING_LENG], unit_str[ANSWER_STRING_LENG]; - char fmted[ANSWER_STRING_LENG], correct[ANSWER_STRING_LENG], answer[ANSWER_STRING_LENG]; + char fmted[ANSWER_STRING_LENG], correctans[ANSWER_STRING_LENG], answer[ANSWER_STRING_LENG]; double n_part; double given, target, ratio, fmted_target, target_u, target_l, scale=1.0; double delta; @@ -2947,7 +2957,8 @@ capa_check_ans(ai,ans, error) AnswerInfo outcome = split_num_unit(ans,&n_part,num_str,unit_str); if( outcome > 1 ) { /* with both num and unit parts or only unit part */ if( u_p != NULL ) { - if (UNIT_FAIL == (result = check_correct_unit(unit_str,u_p,&scale))) { + result = check_correct_unit(unit_str,u_p,&scale); + if (check_for_unit_fail(result)) { *error=strsave(unit_str); } } else { /* what to do when no unit is specified but student entered a unit? */ @@ -2959,7 +2970,7 @@ capa_check_ans(ai,ans, error) AnswerInfo result = NO_UNIT; } } - if( (result != NO_UNIT) && (result != UNIT_FAIL) && ( result != UNIT_NOTNEEDED) ) { + if( (result != NO_UNIT) && (!check_for_unit_fail(result)) && ( result != UNIT_NOTNEEDED) ) { if( t == ANSWER_IS_FLOAT ) { target = (double)atof(s); /* real number */ } else { @@ -3020,14 +3031,18 @@ capa_check_ans(ai,ans, error) AnswerInfo { corr_len = strlen(s); input_len = strlen(ans); if( corr_len == input_len ) { - for(idx=0;idxans_fmt; calc_type = p->calc; unit_str[0]=0; - + switch(type) { case ANSWER_IS_INTEGER: case ANSWER_IS_FLOAT: @@ -3108,7 +3124,8 @@ capa_check_answer(p, answer, error) Prob outcome = split_num_unit(answer,&n_part,input,unit_str); if( outcome > 1 ) { /* with both num and unit parts or only unit part */ if( p->ans_unit != NULL ) { - if ( UNIT_FAIL == ( result = check_correct_unit(unit_str,p->ans_unit,&scale) ) ) { + result = check_correct_unit(unit_str,p->ans_unit,&scale); + if (check_for_unit_fail(result)) { *error=strsave(unit_str); } } else { /* what to do when no unit is specified but student entered a unit? */ @@ -3120,7 +3137,7 @@ capa_check_answer(p, answer, error) Prob result = NO_UNIT; } } - if( (result != NO_UNIT) && (result != UNIT_FAIL) && ( result != UNIT_NOTNEEDED) ) { + if( (result != NO_UNIT) && (!check_for_unit_fail(result)) && ( result != UNIT_NOTNEEDED) ) { if( type == ANSWER_IS_FLOAT ) { target = (double)atof(correct); /* real number */ } else { @@ -3181,13 +3198,18 @@ capa_check_answer(p, answer, error) Prob { corr_len = strlen(correct); input_len = strlen(answer); if( corr_len == input_len ) { - for(ii=0;ii tol ) { outcome = INCORRECT; } } @@ -3390,7 +3412,7 @@ Problem_t *p; char **answers; int cnt; c done = ii = 0; result = 0; while( !done ) { /* check if any of the outcome has failed on units */ - if( (outcomes[ii] == UNIT_FAIL) || + if( (check_for_unit_fail(outcomes[ii])) || (outcomes[ii] == NO_UNIT) || (outcomes[ii] == UNIT_NOTNEEDED) ) { result = outcomes[ii]; @@ -3437,7 +3459,7 @@ Problem_t *p; char **answers; int cnt; c } } for (ii=0;iians_list; while( (iians_cnt) && ( (result != EXACT_ANS) && (result != APPROX_ANS) ) ) { - if((ii!=1)&&((result==UNIT_FAIL)||(result==SIG_FAIL)||(result==UNIT_NOTNEEDED))) { + if((ii!=1)&&((check_for_unit_fail(result))||(result==SIG_FAIL)||(result==UNIT_NOTNEEDED))) { capa_mfree((char*)error); } result = capa_check_ans(ai,answers[0],error);