Posts

Showing posts with the label using if-else statement

if-else statement in C plus plus

Image
The if-else statement in C++ The if then else statement is used when the question is not whether to execute a statement or statements, but which statement or statements to execute. The simplest if-else construct consists of two options, and its format is: If (logical expression) statement 1 or block 1; else statement 2 or block 2; next_statement If logical expression is TRUE, statement1 (or block1) is executed and then next_statement is executed. If logical expression is FALSE, statement2 (or block2) is executed and then next_statement is executed. For e.g., the following program segment informs the user concerning the existence of real solutions in the quadratic equation. Let a, b, c be the coefficients of the quadratic equation. Then if the roots are real, the discriminate d=b 2 -4ac will be greater than or equal to zero.i.e., D=b*b-4*a*c; If(d>=0) then Message: “roots are real” else Message: “roots are imaginary” For e.g., The following program segme...