그레이드 계산기에서 문제를 찾아내는 데 도움이 필요합니다. 이 프로그램은 사용자가 "A 또는 a"와 같은 문자 등급을 입력 할 때 출력이 4.0 인 경우 작동합니다. 하지만 내가 문제가되는 문제는 사용자가 "A + 또는 A-"를 "+ 또는 - add가 0.3 또는 -0.3을 문자 등급"으로 삽입 할 때 PLus 또는 Minus 값을 더하지 않는다는 것입니다.C++ 그레이드 계산기 이슈
const double Plus = 0.3;
const double Minus = 0.3;
/**
* Letter grades are A, B, C, D, and F, possibly followed by + or –.
* Their numeric values are 4, 3, 2, 1, and 0. In our scheme, there is no F+ or F–,
* or A+. Adding a + to the grade increases the numeric value by 0.3, a – decreases it
* by 0.3.
*
* Input: The letter of Grade with + or -.
* Output: The value of inserted grade.
*
* @param cin the standard input stream.
* @param cout the standard output stream.
* @return 0 for success.
*/
int run(istream& cin, ostream& cout)
{
// Enter your letter grade: C+
//Grade value is[2.3]
char list [26] = { "A, B, C, D, F, a, b, c, f" };
char grade;
double value;
cout << "Enter your letter grade: ";
cin >> grade;
cout << fixed << setprecision(1);
if ((grade == 'A' || grade == 'a')){
value = 4.0;
}
else if ((grade == 'A+') || (grade == 'a+')){
value = 4.0 + 0.3;
}
else if (grade == 'A-' || grade == 'a-'){
value = (4.0 - Minus);
}
else if (grade == 'B' || grade == 'b'){
value = 3.0;
if (grade == 'B+' || grade == 'b+'){
value = (3.0 + Plus);
}
else if (grade == 'B-' || grade == 'b-'){
value = (3.0 - Minus);
}
}
else if (grade == 'C' || grade == 'c'){
value = 2.0;
if (grade == 'C+' || grade == 'c+'){
value = (2.0 + Plus);
}
else if (grade == 'C-' || grade == 'c-'){
value = (2.0 - Minus);
}
}
else if (grade == 'D' || grade == 'd'){
value = 1.0;
if (grade == 'D+' || grade == 'd+'){
value = (1.0 + Plus);
}
else if (grade == 'D-' || grade == 'd-'){
value = (1.0 - Minus);
}
}
else if (grade == 'F' || grade == 'f'){
value = 0.0;
if (grade == 'F+' || grade == 'f+'){
value = (0.0 + Plus);
}
else if (grade == 'F-' || grade == 'f-'){
value = (0.0 - Minus);
}
}
else if (!(grade == list[26])){
cout << "INVALID LETTER GRADE" << endl;
value = 0;
}
cout << "Grade value is [" << value << "]" << endl;
return 0;
}
'char 등급 '이므로 ** A + **에서'A '만 캡처합니다. .. – DOOM
모든 경고가 활성화 된 상태에서 컴파일하십시오. A +는 몇 자입니까? – Leiaz
스위치 케이스를 사용하는 것이 더 좋습니다 .. 너무 많은 오류가 있습니다 ... 코드가 + 또는 -를 확인하지 않습니다 – mlwn