Question

Write a C++ Program Write a program that prompts the user to input a number. The program should then output the number and a

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {
    int n;
    
    cout<<"Enter an integer: ";
    cin>>n;
    
    // Checking n is zero
    if(n==0){
        cout<<"zero"<<endl;
    }
    // Checking n is greater than zero
    else if(n>0){
        cout<<"positive"<<endl;
    }
    // Checking n is less than zero
    else{
        cout<<"negative"<<endl;
    }
   
   return 0;
}

Output:

Enter an integer: 5 positive

Add a comment
Know the answer?
Add Answer to:
Write a C++ Program Write a program that prompts the user to input a number. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that write a value-returning function, isVowel, that returns the value true if a...

    Write a program that write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID */ using namespace std; #include <iostream> using namespace std; bool isVowel(char ch); int main() {     char ch;     …     …         ...

  • Write code that prompts the user to input a number. The program should then output the...

    Write code that prompts the user to input a number. The program should then output the number and a message saying whether the number i "Positive, "Negative" or "Zero". It should further output whether the number is odd or even (zero is counted as even) For example:

  • Write a program that prompts the user to input a string. The program then uses the...

    Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. #include <iostream> #include <string> using namespace std; void removeVowels(string& str); bool isVowel(char ch);...

  • Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...

    Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt, and displays data for the specified record. If the record does not exist, display the following error message: No records found for p# using System; using static System.Console; using System.IO; class FindPatientRecords { static void Main() { // Your code here } }

  • Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt,...

    Write the program FindPatientRecords that prompts the user for an ID number, reads records from Patients.txt, and displays data for the specified record. If the record does not exist, display the following error message: No records found for p# using System; using static System.Console; using System.IO; class FindPatientRecords { static void Main() { // Your code here } }

  • C++ Program Write a do-while loop that continues to prompt a user to enter a number...

    C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...

  • Write a program in C++ that prompts the user to input the name of a text...

    Write a program in C++ that prompts the user to input the name of a text file and then outputs the number of words in the file. You can consider a

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • Write a program that (in the main program) prompts the user for the (integer) model number...

    Write a program that (in the main program) prompts the user for the (integer) model number of their car. The main function should then call the function check defective which should • take in the model number of the car • check if the model number is 119, 179, 221, 780, or anything between 189 and 195, inclusive, which indicates the car is defective • print a message indicating whether or not the car is defective Note: this is should...

  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT