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.


How do you order integers from greatest to least with negative and positive numbers?

To order integers from greatest to least, start by identifying the largest number, which will be the highest positive integer or the least negative integer. Compare the positive numbers first, placing them in descending order, and then compare the negative numbers, placing them in ascending order (since they are less than zero). Finally, combine both groups, ensuring that all positive numbers precede the negative numbers. For example, the order of -3, 2, -1, and 4 would be 4, 2, -1, -3.


How do you order integers in decreasing order?

To order integers in decreasing order, start by identifying the largest integer in the set and place it first. Continue comparing the remaining integers, placing the next largest one next in line, and repeat this process until all integers are arranged from the largest to the smallest. Ensure that you consider both positive and negative integers, with positive integers being larger than negative ones. You can also use sorting algorithms or functions in programming languages to automate this process.


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.


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?


Sum of integers?

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


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.