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

  • Home
  • SEARCH
  • 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 8698755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:47:41+00:00 2026-06-13T01:47:41+00:00

I have a programming assignment where I need to encrypt a 4 digit int,

  • 0

I have a programming assignment where I need to encrypt a 4 digit int, input by user. I have split the int into four separate values and the encrypt and decrypt functions work. My problem is when I put the four separate ints back together, some numbers encrypt to zero (eg. in:1234 out:0189) and I want to store the output into an int for use with other functions.

Right now I have a half-baked solution that prints 0 first if the first int is 0.

void joinInt(){
    if(int1 == 0) {cout << 0;}
    joined = int1 * 1000;
    joined += int2 * 100;
    joined += int3 * 10;
    joined += int4;
    cout << joined << endl;
    }

My goal is to return joined (with the leading zero) rather than just print it within the function.

  • 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-13T01:47:41+00:00Added an answer on June 13, 2026 at 1:47 am

    An int basically stores leading zeros. The problem that you are running into is that you are not printing the leading zeros that are there.

    Another, different approach is to create a function that will accept the four int values along with a string and to then return a string with the numbers.

    With this approach you have a helper function with very good cohesion, no side effects, reusable where you need something similar to be done.

    For instance:

    char *joinedIntString (char *pBuff, int int1, int int2, int int3, int int4)
    {
        pBuff[0] = (int1 % 10) + '0';
        pBuff[1] = (int2 % 10) + '0';
        pBuff[2] = (int3 % 10) + '0';
        pBuff[3] = (int4 % 10) + '0';
        pBuff[4] = 0;                    // end of string needed.
        return pBuff;
    }
    

    Then in the place where you need to print the value you can just call the function with the arguments and the provided character buffer and then just print the character buffer.

    With this approach if you have some unreasonable numbers that end up have more than one leading zero, you will get all of the zeros.

    Or you may want to have a function that combines the four ints into a single int and then another function that will print the combined int with leading zeros.

    int createJoinedInt (int int1, int int2, int int3, int int4)
    {
        return (int1 % 10) * 1000 + (int2 % 10) * 100 + (int 3 % 10) * 10 + (int4 % 10);
    }
    
    char *joinedIntString (char *pBuff, int joinedInt)
    {
        pBuff[0] = ((joinedInt / 1000) % 10) + '0';
        pBuff[1] = ((joinedInt / 100) % 10) + '0';
        pBuff[2] = ((joinedInt / 10) % 10) + '0';
        pBuff[3] = (joinedInt % 10) + '0';
        pBuff[4] = 0;                    // end of string needed.
        return pBuff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for a programming assignment, I have to load a tree into an array in
For a programming assignment, we have the following requirements: It needs to be a
For my second programming assignment in my Java class, we have to create a
I'm rushing against the clock for a programming assignment in which I have to
I have completed the assignment (yes it is for a programming class), but I
I have been programming in .NET for four years (mostly C#) and I use
I need to implement a chess game for a school assignment, and you have
I am new to the Go programming language and I have an assignment to
I have this programming assignment that converts between meters and feet, and between kilograms
Hello I have one c++ Programming assignment question. I tried hard but somehow I

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.