0

A few questions regarding C++

1) Does an 'If' statement allow the use of addition/subtraction/multiplication/etc within it's condition? Ex. if (b[0]+b[1]+b[2]==3||12) {'execute code'} Note. b is a 3 int array for this example. 2) Is it possible to cout nothing while representing an integer? Ex. cout << b[2] << endl; //shows an empty space, even if b[2] has a value of, let's say, 0.

19th Jan 2017, 4:39 PM
Jerico Landry
3 odpowiedzi
+ 2
#include <iostream> using namespace std; int main() { int b[] = {1, 2, 3}; if ((b[0]+b[1]+b[2])== 3 || (b[0]+b[1]+b[2])== 12){ //some code cout << "Success!\n" ; } else{cout << "Failure! \n";} } //Outputs "Failure!" ================================================ This will work for you, but consider assigning the sum to an integer because it's very unweildy in that form.
19th Jan 2017, 5:03 PM
Aaron
Aaron - avatar
+ 1
If you want an empty space, use : cout<<' ';
19th Jan 2017, 5:05 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
0
Thank you Aaron. And I will test your Method Prunier.
19th Jan 2017, 5:19 PM
Jerico Landry