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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:31+00:00 2026-06-09T12:33:31+00:00

I was trying the Open Courseware CS106b assignment 1. I am getting stuck on

  • 0

I was trying the Open Courseware CS106b assignment 1. I am getting stuck on problem 4 which requires the use of recursion to write an integer to string convertor. We are not allowed to use any library functions that perform integer conversions.

The problem is that after every ‘recursion level’ the code does not keep track of the previous string, thus I am not able to append and build-onto the string.

 #include <iostream>
 #include <string>
 #include "console.h"
 #include "simpio.h"
 using namespace std;

/* Function prototypes */

string intToString(int n);
int stringToInt(string str);

/* Main program */

int main() {
    // [TODO: fill in the code]
    int n = getInteger("Enter number for conversion to String: ");
    cout<< "Converted to String: "<<intToString(n);
    return 0;
}

//Functions

string intToString(int n){
    double toBeDecomposed = n;
    string convertedToString;
    char ch;
    string tempString;

    if((double)(toBeDecomposed/10) >= 0.1){

        int lastDigit = (int)toBeDecomposed%10;

        toBeDecomposed = (int)(toBeDecomposed/10);

        intToString(toBeDecomposed);

        if (lastDigit == 0) {
            ch = '0';
        }
        else if (lastDigit == 1) {
            ch = '1';
        }
        else if (lastDigit == 2) {
            ch = '2';
        }
        else if (lastDigit == 3) {
            ch = '3';
        }
        else if (lastDigit == 4) {
            ch = '4';
        }
        else if (lastDigit == 5) {
            ch = '5';
        }
        else if (lastDigit == 6) {
            ch = '6';
        }
        else if (lastDigit == 7) {
            ch = '7';
        }
        else if (lastDigit == 8) {
            ch = '8';
        }
        else if (lastDigit == 9) {
            ch = '9';
        }

        tempString = string() + ch;

        convertedToString = convertedToString.append(tempString);

        cout<<convertedToString<<endl;

    }
    cout<<"Returning: "<<convertedToString<<endl;

    return convertedToString;
}

int stringToInt(string str){
    return 0; 
}

My debugging output shows that it only returns the last digit:

enter image description here

Can anyone suggest how to successfully append to the string ConvertedToString so that I return the whole converted integer?

  • 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-09T12:33:32+00:00Added an answer on June 9, 2026 at 12:33 pm

    You aren’t doing anything with the result of your recursive function call.

    The hint is that intToString returns a string. You’re ignoring that return value when you call intToString(toBeDecomposed);.

    Capture that return value and do something with it.

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

Sidebar

Related Questions

when trying to open report server url http://<>/Report server i am getting error /
I am trying to open a file which a user can set. In other
I'm trying open a txt file and read it, but I'm getting a type
i'm trying to open new Calc document, and i'm getting this error: System.IO.FileLoadException: Mixed
I'm trying to open an .html file as one big long string. This is
Im trying to open a file. Here is my output (string i build up
I am trying to open a batch file which is opened by another batch
I am trying open a new window using url.Action. And the new Window url
I am trying open a very large file in Emacs and it fails to
I´m trying to open a tab using jquery, here is my code: $(#ecContenedorFolders).tabs({ tabTemplate:

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.