Снова условный оператор - C (СИ)
Формулировка задачи:
Опять же вопрос с условным оператором, недопонимания у нас с СИ, почему он не хочет слушать этот условный оператор
Полностью условие...
else if ( a==1 && currentGrade < 0)
//weightFinal
printf("Enter the weight of the final: ");
int a = scanf("%lf", &weightFinal);
if ( a == 1 && currentGrade >= 0 && currentGrade <= 100 ) {
currentGrade = ( currentGrade*(1 - (weightFinal*0.01)) ); //converting currentGrade to CommonGrade. If currentGrade = 100, Common Grade will be other, it depends on weight of exam
necessaryCommonGrade = desireGrade - currentGrade; //90 - 58 = 32 it's necessary examgrade to get desired grade 31.899
needGradeExam = (necessaryCommonGrade / weightFinal)*100 ; // 32 / 30 = 106.66 converting examgrade in procents
if(needGradeExam >=0)
printf ("You need to get at least %.2lf%c on the final to get a %c in the class.", needGradeExam,'%',LetterGrade); // 2 numerals after base
else
printf ("You cannot score low enough on the final to get a %c in the class.", LetterGrade);
}
else if ( a==1 && currentGrade < 0) {
printf ("The number you last entered should have been positive. Ending program.");
_Exit (EXIT_SUCCESS);
}
else {
printf("Invalid formatting. Ending program.");Решение задачи: «Снова условный оператор»
textual
Листинг программы
else if ( a==1 && currentGrade < 0)
если ввожу отрицательное число, он не выполняет команду вывода надписи "The number you last entered should have been positive. Ending program."
else if ( a==1 && currentGrade < 0) {
printf ("The number you last entered should have been positive. Ending program.");
_Exit (EXIT_SUCCESS);
}
Объяснение кода листинга программы
В данном коде выполняется следующая последовательность действий:
- Проверяется условие
a==1 && currentGrade < 0. Если это условие истинно, то выполняется следующий блок кода. - Выводится сообщение
The number you last entered should have been positive. Ending program.. - Код вызывает функцию
_Exit(EXIT_SUCCESS). Это приводит к завершению работы программы с кодом успеха. Таким образом, если пользователь вводит отрицательное число, то программа выведет сообщение об ошибке и завершит свою работу.