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 8196821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:36:25+00:00 2026-06-07T05:36:25+00:00

I am stuck with my solution to problem 4 of Project Euler, I have

  • 0

I am stuck with my solution to problem 4 of Project Euler, I have the following code which should work and it does iterate through the solution to the problem as I have researched and discovered (993*913):

// Michael Clover
// Project Euler
// Problem 4

/* A palindromic number reads the same both ways. The largest palindrome made from the    product of two 2-digit numbers is 9009 = 91  99.

Find the largest palindrome made from the product of two 3-digit numbers. */

#include <iostream>
#include <string>
#include <sstream>
#include <cstdlib>

using namespace std;

bool achieved = false; // change to true when the palindrome is found
string string_conversion = "";
string first_half = ""; // first half of string
string second_half = ""; // second half of string
stringstream conversion; // use this to convert integers to strings

int check(string first_half, string second_half) {
    if (first_half.compare(second_half) == 0) {
        achieved = true;
        return 0;
    }
    else {
        return 0;
    }
    return 0;
}

int convert(int result) {
    char temp;
    conversion << result;
    conversion >> string_conversion;
    if (string_conversion.size() == 6) {
        temp = string_conversion.at(0);
        //cout << "temp = " << temp << endl;
        first_half+=(temp);
        temp = string_conversion.at(1);
        //cout << "temp = " << temp << endl;
        first_half+=(temp);
        temp = string_conversion.at(2);
        //cout << "temp = " << temp << endl;
        first_half+=(temp);
        temp = string_conversion.at(5);
        //cout << "temp = " << temp << endl;
        second_half+=(temp);
        temp = string_conversion.at(4);
        //cout << "temp = " << temp << endl;
        second_half+=(temp);
        temp = string_conversion.at(3);
        //cout << "temp = " << temp << endl;
        second_half+=(temp);
        //cout << first_half << second_half << endl;
        check(first_half, second_half);
    }
    //if (string_conversion.size() == 5) {
        //cout << "The size of the string is 5" << endl;
        //exit(1);
    //}
    string_conversion = "";
    cout << first_half << endl;
    cout << second_half << endl;
    first_half.clear();
    second_half.clear();
    conversion.clear();
    conversion.str("");
    //cout << "conversion: " << conversion << endl;
    return 0;
}

int iterate(int operator_one, int operator_two) { // takes two numbers and iterates     through them, each time it is iterated, the result is passed to the convert    function to convert to string
    int two = operator_two;
        for (int i = operator_one; i > 100; i--) {
            int result = i * two;
            cout << i << "x" << two << endl;
            convert(result);
        }
    return 0;
}

int main() { // Use the stringstream to convert the numerical values into strings     which you can then use to check if they are palindromes
    int operator_one = 999;
    int operator_two = 999;
    while (achieved == false) {
        for (int i = operator_two; i > 100; i--) {
            iterate(999, i);
        }
    }
    cout << "The largest palindrome made from the product of two 3-digit numbers is: "     << string_conversion << endl;
    return 0;
}

This program iterates through all of the numbers through 999×999 downwards and then splits the 6-digit numbers into two strings with the second half of the result being arranged from back to front. As shown in the console using cout << during runtime, the program tries 993*913 and both the second_half string and the first_half string contain 906. What I thought the program should then do is perform the check(string first_half, string second_half) function after iterating this and decide that both of the strings match (which should according to various sources return 0) this should then initiate the if statement within check() and set the boolean achieved to true ending the program within the main statement and printing the result before exiting the program. It does not do this however and this is my problem. Thank you for any and all 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-07T05:36:26+00:00Added an answer on June 7, 2026 at 5:36 am

    Leaving aside some other issues I see in this code, I think your termination problem is because you only check achieved after the outer loop in main() is finished. So the inner loop (iterate()) will continue until operator_one falls below 100 and then the outer loop will continue until operator_two falls below 100 before you actually check your termination condition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope to get solution to this problem. I have been stuck on it since
i've stuck with problem. I have an ASP.NET project with dynamically creating controls. Even
I am stuck with a following problem: built a small application in asp.net, which
I am stuck in a situation from which I am finding no solution. Let
Project Euler problem 36 states: The decimal number, 585 = 1001001001 (binary), is palindromic
I am attempting to make an algorithm to solve Project Euler Problem 255 I
Possible Duplicate: Need help solving Project Euler problem 200 Similar to this question Project
I am stuck with a programming problem: I have two Java projects, in my
We have a VS 2003 solution containing 1 vb project and several c# projects(No
I have searched and searched for a solution to this problem, but it seems

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.