update : handle division with zero & runtime error (#19620)

This commit is contained in:
Thomas Papapaschos
2018-10-23 16:50:19 +03:00
committed by Kristofer Koishigawa
parent 4d0fad6e75
commit b7836f87db

View File

@ -169,7 +169,7 @@ In the above pseudocode, suppose the value of n is equal to constant2. The compi
The break statement is used to prevent the code running into the next case. The break statement is used to prevent the code running into the next case.
### Example: ### Example:
``` ```C
// Program to create a simple calculator // Program to create a simple calculator
// Performs addition, subtraction, multiplication or division depending the input from user // Performs addition, subtraction, multiplication or division depending the input from user
@ -202,6 +202,11 @@ int main()
break; break;
case '/': case '/':
if(secondNumber==0){
printf("division with zero is not allowed\n");
break;
//Avoid runtime error of division with zero
}
printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/secondNumber); printf("%.1lf / %.1lf = %.1lf",firstNumber, secondNumber, firstNumber/secondNumber);
break; break;