Posts

Showing posts with the label if

Write an if statement that increases pay by 3% if score is greater than 90.

 Write an if statement that increases pay by 3% if score is greater than 90. #include<iostream> using namespace std; int main() { float pay = 10; int score; cout<<" enter your score :"; cin>>score; if(score > 90) { pay = pay + pay* 3/100; } cout<<"you win price :"<<pay<<endl; return 0; } output:-  enter your score :29 you win price :10  enter your score :100 you win price :10.3

Write an if statement that assigns 1 to x if y is greater than 0.

 Write an if statement that assigns 1 to x if y is greater than 0. /* Write an if statement that assigns 1 to x if y is greater than 0. */ #include<iostream> using namespace std; int main() { int x; int y; cout<<" enter positive or negative number :"; cin>>y; if(y > 0) { x=1; } if(y < 0) { x=0; } cout<<" x is "<<x; return 0; } output:-  enter positive or negative number :123  x is 1  enter positive or negative number :-123  x is 0

checking the input number is even or not

 checking the input number is even or not #include<iostream> using namespace std; int main() { //checking the input number is even or not int num; cout<<"enter a number :"; cin>>num; if(num%2 == 0) { cout<<num<<" number is even number"; } if(num%2 != 0) { cout<<num<<" number is odd number"; } return 0; } output :- enter a number :2 2 number is even number enter a number :1 1 number is odd number

if nested in Cpp

 if inside if syntax in cpp #include<iostream> using namespace std; int main() { if(true) { cout<<"first true"<<endl; if(true) { cout<<"second true"<<endl; if(true) {    cout<<"third true"<<endl; } if(false) { //not show output } } if(false) { //not show output } } return 0; }

if syntax in c++

 if syntax in c++ #include<iostream> using namespace std; int main() { //this statment is show output if(true) { cout<<"it is true"<<endl; } if(1) { cout<<"it is also true"<<endl; } //this statment not show output if(false) { cout<<"it is false "<<endl; } if(0) { cout<<"it is also false"<<endl; } return 0; }