how can we code , like value of a+ value of b, if sum is 100 how can we put a if statement stating if value < 100 cout you tried hard...sometimes like that , I mean to say how can we combine a normal addition and subtraction with if statement. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how can we code , like value of a+ value of b, if sum is 100 how can we put a if statement stating if value < 100 cout you tried hard...sometimes like that , I mean to say how can we combine a normal addition and subtraction with if statement.

19th Jul 2016, 11:06 PM
Khan Zeeshan
Khan Zeeshan - avatar
4 Answers
+ 2
i would do int math; cout what math? 1= Add, 2= Sub cin math//User input if(math ==1) { if(a+b < 50) cout sorry else { cout wo } } elseif(math ==2) if(a-b < 100) cout sorry } else { cout wo } } else { cout no matching math found } sure there are better solutions out there, but for the beginning its the simplest I got in mind this quick. btw instead of using if Statements you could also use a switch
19th Jul 2016, 11:48 PM
Steven
Steven - avatar
0
don't know if I get you right but if((a+b < 100) || (a-b <100)) { cout << "Sum is less" << endl; } else { cout << "match 100" << endl; }
19th Jul 2016, 11:28 PM
Steven
Steven - avatar
0
I mean this way
19th Jul 2016, 11:33 PM
Khan Zeeshan
Khan Zeeshan - avatar
- 2
#include <iostream> using namespace std; int main() { int a = 30; int b = 12; int sum = a + b; if (sum>50){cout<<"wow"<<endl; }else {cout<<"sorry"<<endl; } return 0; }
19th Jul 2016, 11:33 PM
Khan Zeeshan
Khan Zeeshan - avatar