Rearrange the code to declare two integer variables: a and b, print to the screen the division equation a/b. If b is equal to 0, | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Rearrange the code to declare two integer variables: a and b, print to the screen the division equation a/b. If b is equal to 0,

9th Mar 2017, 6:12 AM
Sunita Sharma
2 Answers
+ 6
b=0 is an runtime error... coz a/b while b=0 is undefined in maths... if it would have been java u could have used try catch block to handle it.... search about exception handling in c++ for d answer
9th Mar 2017, 6:25 AM
Ronit Kumar
Ronit Kumar - avatar
+ 1
#include<iostream> #include<cmath> using namespace std; int main() { Int a,b; a=12 //assign values for a and b b= 2 If (b==0) { cout<<"invalid value\n";} else cout<< a/b ; Return 0; }
9th Mar 2017, 6:25 AM
itumeleng
itumeleng - avatar