Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:31:56+00:00 2026-06-15T17:31:56+00:00

I may not have explained this very well in the title simply because I

  • 0

I may not have explained this very well in the title simply because I don’t really know how to explain it in the length a title has so I apologize for that. Anyways this is my current code:

// Gets the product that is used to get the factors
cout << "Enter a number that you want to be factored" << endl;
cin >> y;

system("cls");

// Gets the sum from the user that the two factors need to add up to
cout << "Input the sum that is needed" << endl;
cin >> neededSum;

secondary = y;
system("cls");

// Lists the factors that add up to the specified sum
cout << "The numbers that add up to " << neededSum << " are:" << endl;
for (int i = 0; i < 100; i++)
{
    x++;
    increment++;
    y = secondary / x;
    product = x * y;
    if (product == secondary)
    {
        sum = x + y;
        if (sum == neededSum)
        {
            cout << x << " and " << y << endl;
        }
    }
}

Basically it takes a product lists all the factors of that product. Then, it adds all of the factors together until it finds the one that adds up to the specified sum.

However, if the specified sum is negative like ‘-11′ for instance it won’t work because the factors of ’28’ (an example) are 4 and 7 not -4 and -7. I need to figure out a way to fix this so it knows when it has to be -4 and -7 instead of the positive reverse.

Thanks in advance for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:31:57+00:00Added an answer on June 15, 2026 at 5:31 pm

    Just pretend that x and y are negative:

    if (product == secondary)
    {
        sum = x + y;
        if (sum == neededSum)
        {
            cout << x << " and " << y << endl;
        }
        else if (-sum == neededSum)
        {
            cout << -x << " and " << -y << endl;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this question probably wont be explained very well and that's because I don't really
Ok, the title may not be the most descriptive. It's easier to explain with
I think this may not have anything to do with the area tags, but
This may sound very basic... can someone please explain the use of the toString()
Not sure if my title explains it very well so here's an example. I
I have a datagridview that may or may not have rows selected when the
I have an unweighted directed graph that may or may not have cycles in
I have a byte array that may or may not have null bytes at
My situation: ClassA may or may not have a parent of type ClassB .
I have a bunch of models that may or may not have a property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.