Write a program that prompts the user to input a number. The program should then output the number and a message saying whether the number is positive, negative, or zero.
#include <iostream>
int main()
{
  std::cout << "Enter the number: ";
  int number;
  std::cin >> number;
  if(!std::cin)
  {
    std::cerr << "Bad input\n";
    return 1;
  }
  Â
  std::cout << "The number '" << number << "' is ";
  Â
  if(number == 0)
  {
    std::cout << "zero\n";
  }
  else
  if(number > 0)
  {
    std::cout << "positive\n";
  }
  else
  {
    std::cout << "negative\n";
  }
  return 0;
}
Comments
Leave a comment