

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























int main(){ int sum = 0, quot; int a, b; for (int i = 0; i < 10; i++){ GetNumbers(a,b); quot = Quotient(a,b); sum += quot; OutputQuotient(a,b,quot); } cout << “\nSum of ten quotients is ”<< sum; return 0; }
Enter two integers
10
10
Quotient of 10 and 10 is 1
Enter two integers
10
0
Program terminated abnormally
int Quotient (int a, int b ) { if(b == 0){ cout << “Denominator can’t “ << “ be zero” << endl; // Do local clean up exit(1); } return a / b; }
Enter two integers
10
10
Quotient of 10 and 10 is 1
Enter two integers
10
0
Denominator can’t be zero
int Quotient(int a, int b){ if(b == 0) b = 1; OutputQuotient(a, b, a/b); return a / b ; } int main() { int a,b,quot; GetNumbers(a,b); quot = Quotient(a,b); return 0; }
Enter two integers
10
0
Quotient of 10 and 1 is 10
bool Quotient ( int a, int b, int & retVal ) { if(b == 0){ return false; } retVal = a / b; return true; }
for(int i = 0; i < 10; i++){ GetNumbers(a,b); while (! Quotient(a, b, quot) ) { cout << “Denominator can’t be ” << “Zero. Give input again \n”; GetNumbers(a,b); } sum += quot; OutputQuotient(a, b, quot); }
int main() {
function1(); function2(); function3();
return 0;
}
int main(){ if( function1() ) { if( function2() ) { if( function3() ) { ... } else cout << “Error Z has occurred”; } else cout << “Error Y has occurred”; } else cout << “Error X has occurred”; return 0; }