Answer to Question #183003 in C++ for Vincenzo Santoro

Question #183003

Instructions

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.


1
Expert's answer
2021-04-23T15:40:21-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS