0

How to code like this? The user has to put value of a and b. Must a>0 and a>b. Thanks

6th Nov 2016, 2:37 PM
Rahimi Hanis Abdul
Rahimi Hanis Abdul - avatar
3 Answers
+ 1
You can use assert function to make sure that user enter values as per your conditions. If the condition fails, program stops showing an error. For example: #include<iostream> #include<cassert> using namespace std; int main() { int a,b; cin>>a; cin>>b; assert(a>0 && a>b); cout<<a; } You can also use try catch blocks.
6th Nov 2016, 2:59 PM
kamal joshi
kamal joshi - avatar
0
1.get the user input values by cin 2. if(a<0 || b>a) , print "value of a should be greater than 0 and value of b should NOT be greater than a
6th Nov 2016, 2:52 PM
Ziyaan Hassan
Ziyaan Hassan - avatar
0
I have done the code it seems that the program isn't running anymore when I put the wrong statement ex: a=-6
6th Nov 2016, 4:10 PM
Rahimi Hanis Abdul
Rahimi Hanis Abdul - avatar