answersLogoWhite

0

#include

#include

#include

#include

using namespace std;

string ask(string prompt)

{

string input;

cout<

getline(cin, input);

return(input);

}

int ask_for_int()

{

int input;

string response = ask("Enter a number: ");

stringstream s(response);

if(s>>input)

return(input);

return(0);

}

bool ask_yn(std::string prompt)

{

while(1)

{

string input = ask(prompt);

if( input.size() && input.size()<4 )

{

if((input[0]=='y' input[0]=='Y')

&& (input.size()==1

(input.size()==3

&& (input[1]=='e' input[1]=='E')

&& (input[2]=='s' input[2]=='S'))))

return(true);

if(( input[0]=='n' input[0]=='N')

&& (input.size()==1

(input.size()==2

&& (input[1]=='o' input[1]=='O'))))

return(false);

}

cout<<"Please answer YES or NO\n"<

}

}

void print_array(string title, vector arr)

{

cout<

if(!arr.size())

cout<<"None"<

else for(size_t i=0; i

cout<

cout<

}

int main()

{

vector positive;

vector negative;

while(1)

{

int i = ask_for_int();

if( !i && !ask_yn("Invalid number. Continue entering numbers? "))

break;

if( i>0 )

positive.push_back(i);

else

negative.push_back(i);

}

cout<

print_array("Positive integers",positive);

print_array("Negative integers",negative);

}

Example Output

Enter a number: 42

Enter a number: -12

Enter a number: -1

Enter a number: 2112

Enter a number: 6

Enter a number: -23

Enter a number: +1

Enter a number: -990

Enter a number: 112

Enter a number: 0

Invalid number. Continue entering numbers? no

Positive integers

42

2112

6

1

112

Negative integers

-12

-1

-23

-990

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Do integers have to have an opposite or just be a positive or negative number?

An integer is just a whole number, excluding zero. Any positive integer will always have an opposite just by placing a negative sign in front of the positive integer. You can also say that any negative whole number is an integer.


When you subtract a positive from a negative will it always be negative?

yes it will be. yes... if (-3)-5 is a possible problem, then the answer will be -8... it is like removing the negative signs, adding, then placing back the negative sign


How do you order negative decimals?

by ordering it like a number line. negatives goes first then positive. but the placing of the numbers are also included


Can negative numbers be written as fractions?

Yes, negative numbers can be expressed as fractions. A negative number can be represented as a fraction by placing it over 1, such as -3 can be written as -3/1. Additionally, any negative fraction, like -2/5, is also a valid representation of a negative number. Thus, both integers and rational numbers in negative form can be written as fractions.


How does placing batteries in parallel boost the total voltage?

Placing batteries in parallel increases the total voltage because the positive terminals are connected together and the negative terminals are connected together, which allows the voltage of each battery to add up.


Sum of integers?

Placing a question mark at the end of a phrase does not make it a sensible question.


Input a number and find whether it is positive or negative?

Placing a question mark at the end of a statement does not make it a sensible question. Try to use a whole sentence to describe what it is that you want answered.Yes, it is possible to input a number and find whether it is positive or negative. Yes, it is possible to write an algorithm to do that. But what is it that you want?


What are the positive and negative effects of trust?

When you trust others you feel freer. However, placing too much trust in others may set you up to be taken advantage of by others.


Which of the constinents is located entirely in quadrant ii?

Europe is the continent located entirely in Quadrant II of the Cartesian coordinate system. This quadrant is defined by positive y-values and negative x-values, placing Europe entirely in the region where longitude is negative (west of the Prime Meridian) and latitude is positive (north of the Equator).


How can one effectively draw electric field lines?

To effectively draw electric field lines, start by placing positive charges as the source and negative charges as the sink. Draw lines that start at positive charges and end at negative charges, with the lines closer together indicating stronger electric fields. Remember that electric field lines never cross and always point away from positive charges and towards negative charges.


Set of positive integers?

Placing a question mark at the end of some words does not make it a sensible question. There is insufficient information for us to even begin to understand this question. Please edit the question to include more context or relevant information.


How do you charge a capacitor?

You charge a capacitor by placing DC voltage across its terminal leads. Make sure when using a polarized capacitor to place positive voltage across the positive lead (the longer lead) and negative voltage across the negative lead. Also make sure that the voltage you charge the capacitor to doesn't exceeds its voltage rating.