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.
3 Respuestas
+ 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.
+ 1
If you want an empty space, use :
cout<<' ';
0
Thank you Aaron. And I will test your Method Prunier.