Table Of Contents
Previous Section Next Section

Program 24: Overly Simple Division

This program divides two integers. Although it's too simple to fail, it does.

  1 /************************************************
  2  * Simple divide program.                       *
  3  ************************************************/
  4 #include <iostream>
  5
  6 int main()
  7 {
  8     int n1, n2; // Two integers
  9
 10     std::cout << "Enter two integers: ";
 11     std::cin >> n1 >> n2;
 12
 13     if (n2 =! 0)
 14         std::cout << "Result is: " <<
 15             (n1/n2) << '\n';
 16     else
 17         std::cout << "Can not divide by zero\n";
 18
 19     return (0);
 20 }

(Next Hint 70. Answer 25.)

Table Of Contents
Previous Section Next Section