0
How to code like this? The user has to put value of a and b. Must a>0 and a>b. Thanks
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.
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
0
I have done the code it seems that the program isn't running anymore when I put the wrong statement ex: a=-6