Print the square of the input value if the input value is less than 180. - C++ Language Basics

C++ examples for Language Basics:Console

Description

Print the square of the input value if the input value is less than 180.

Demo Code

#include <iostream>
using namespace std;
int main()/*from ww w.jav a 2  s .  c om*/
{
   int num, square;
   cout << "\n\n";  // Print two blank lines.
   cout << "What number do you want to see the square of? ";
   cin >> num;
   if (num <= 180)
   {
      square = num * num;
      cout << "The square of " << num << " is " << square << "\n";
   }
   if (num > 180)
   {
      cout << '\x07';   // BEEP
      cout << "\n* Square is not allowed for numbers over 180 *";
      cout << "\nRun this program again trying a smaller value.";
   }
   cout << "\nThank you for requesting square roots.\n";
   return 0;
}

Result


Related Tutorials