If and If else
Make a condition and run it.
Last updated
Was this helpful?
Was this helpful?
#include<iostream>
using namespace std;
int main () {
int A = 0;
cout<<"Please enter a number to A: "<< endl;
cin >> A;
if(A<5 && A >1){ // two condition need to met
cout<<"Condition met"<<endl;
}
return 0;
}#include<iostream>
using namespace std;
int main () {
int A = 0;
cout<<"Please enter a number to A: "<< endl;
cin >> A;
if(A<8) {
cout<<"A less than 8"<<endl;
}
if(A<6) {
cout<<"A less than 6"<<endl;
}
if(A<4) {
cout<<"A less than 4"<<endl;
}
if(A<7) {
cout<<"A less than 7"<<endl;
}
if(A<5) {
cout<<"A less than 5"<<endl;
}
return 0;
}#include<iostream>
using namespace std;
int main () {
int A = 0;
cout<<"Please enter a number to A: "<< endl;
cin >> A;
if(A == 8) {
cout<<"A equal 8"<<endl;
}
else {
cout<<"A is other number than 8"<<endl;
}
return 0;
}#include<iostream>
using namespace std;
int main () {
int A = 0;
cout<<"Please enter a number to A: "<< endl;
cin >> A;
if(A < 4) {
cout<<"A less than 4"<<endl;
}
else if(A < 3) {
cout<<"A less than 3"<<endl;
}
else if(A < 7) {
cout<<"A less than 7"<<endl;
}
else if(A < 8) {
cout<<"A less than 8"<<endl;
}
else if(A < 9) {
cout<<"A less than 9"<<endl;
}
else {
cout<<"A is 9 or larger"<<endl;
}
return 0;
}