answersLogoWhite

0


Best Answer

You cannot determine the truth of a statement, you can only determine the truth of an expression. However, a statement is merely an expression followed by a semi-colon, so it amounts to the same thing.

Only a Boolean expression can evaluate true or false. Numeric expressions implicitly convert to Boolean; they evaluate true when the result is non-zero. However, any class of object that overloads operator bool() implicitly converts to Boolean. E.g., containers are true when they contain one or more objects while streams are true when their state is good.

The following statement will determine the truth about any Boolean expression:

std::cout << "The expression is " << (expression ? "true" : "false") << "\n";

Example:

int a=0;

int b=42;

std::cout << "The expression " << a << "==" << b << " is " << ((a==b) ? "true" : "false") << "\n";

// false

int c = 0;

double d = 0.0;

std::cout << "The expression " << c << "==" << d << " is " << ((c==d) ? "true" : "false") << "\n";

// true

std::string s {}; // an empty string

std::cout << "The expression "" << s << "" is " << (s ? "true" : "false") << "\n";

// false

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do i write a C plus plus program to output to determine the truth of a statement in a single statement?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why the semicoloumn is used in c program?

Why semicolon? Tradition.What does it do? Terminates a single statement, eg:i+= 3; /* expression is a single statement */{ i= 3; --j; } /* no semicolon after the compound statement */


How the program statement and code are related?

A statement in your program is part of the code. In a low-level programming language, a statement will map directly to a single CPU instruction. In a high-level programming language, a statement is the smallest element of the language's syntax.


Write a program that prints the multiplication table for number 6?

'*** Choose which specific times tables number to print out... intTablesNo%=6 '*** (CL)ear the Output (S)creen... CLS '*** Start of FOR/NEXT loop block statement/loop counts upwards from 1 to 12... FOR intTimesNo%=1 TO 12 '*** PRINT out each times tables number sum... PRINT intTimesNo%; " X "; intTablesNo%; " = "; intTimesNo%*intTablesNo% '*** end of FOR/NEXT loop block statement... NEXT '*** END of program/halt program code execution... END '*** NOTE: Once you understand how the above program works...; ' then, you can safely DELETE all of the explanatory comment statement lines... ' each of which begin with a single apostrophe: ('). -Thanks! ;-)


What are various configurations of differential amplifiers?

Dual input and Balanced output configuration, Dual input and Unbalanced output configuration, Single input and Balanced output configuration and Single input and Unbalanced output configuration


How many leds can be powered from a single 4017 output?

20 led can be powered from a single 4017 output X-ZONE ( PRANJAL)


Single program Uni-programming?

A single program is also known as uni programming. Uni programming only allows on program to be present in the memory at a time. Single program


What is the deffernce of the switch statement and the if statement in c plus plus?

If statement is single selection statement,whereas the switch statement is multiple selective.


How can you determine the polarization axis for a single sheet of Polaroid?

How can you determine the polarization axis for a single sheet of Polaroid?


What are the single and dual alternative selection struction?

Single Alternative Selection Structure is a binary (IF&gt;THEN) statement. IF condition X is met THEN do this. Dual Alternative Selection Structure is when more than one option exists and the statement has the possibility to take the program in different directions, based on the response. IF condition X is met THEN do this, ELSE do something differently.


What is statement and blocks?

A statement is a single instruction in a language; a block is a group of instructions.


What Gate that always inverts its single input as an output?

"not" gate


What are the Types of income statement?

1. Single step income statement 2 &acirc;&euro;&ldquo; Multi-step income statement