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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:33:59+00:00 2026-05-20T22:33:59+00:00

Sorry, I realized that I put in all of my code in this question.

  • 0

Sorry, I realized that I put in all of my code in this question. All of my code equals most of the answer for this particular problem for other students, which was idiotic.

Here’s the basic gist of the problem I put:

I needed to recognize single digit numbers in a regular mathematical expression (such as 5 + 6) as well as double digit (such as 56 + 78). The mathematical expressions could also be displayed as 56+78 (no spaces) or 56 +78 and so on.

The actual problem was that I was reading in the expression as 5 6 + 7 8 no matter what the input was.

Thanks and sorry that I pretty much deleted this question, but my goal is not to give answers out for homework problems.

Jesse Smothermon

  • 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-05-20T22:34:00+00:00Added an answer on May 20, 2026 at 10:34 pm

    First, it helps to move such ifs like this

    userInput[i] != '+' || userInput[i] != '-' || userInput[i] != '*' || userInput[i] != '/' || userInput[i] != '^' || userInput[i] != ' ' && i < userInput.length() 
    

    into its own function, just for the clarity.

    bool isOperator(char c){
      return c == '+' || c == '-' || c == '*' || c == '/' || c == '^';
    }
    

    Also, no need to check that it’s no operator, just check that the input is a number:

    bool isNum(char c){
      return '0' <= c && c <= '9';
    }
    

    Another thing, with the long chain above, you got the problem that you will also enter the tempNumber += ... block, if the input character is anyhing other than '+'. You would have to check with &&, or better with the function above:

    if (isNum(userInput[iterator])){
        tempNumber += userInput[iterator];
    }
    

    This will also rule out any invalid input like b, X and the likes.


    Then, for your problem with double digit numbers:
    The problem is, that you always input a space after inserting the tempNumber. You only need to do that, if the digit sequence is finished. To fix that, just modify the end of your long if-else if chain:

    // ... operator stuff
    } else {
      postfixExpression << tempNumber;
      // peek if the next character is also a digit, if not insert a space
      // also, if the current character is the last in the sequence, there can be no next digit
      if (iterator == userInput.lenght()-1 || !isNum(userInput[iterator+1])){
          postfixExpression << ' ';
      }
    }
    

    This should do the job of giving the correct representation from 56 + 78 --> 56 78 +. Please tell me if there’s anything wrong. 🙂

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

Sidebar

Related Questions

Sorry but this is a concept that I never realized and I never used
Sorry for question but I can't find answer anywhere on internet. I couldn't find
Sorry for this simple question, but I can't solve it... There is an example:
Sorry, I know this question is easy, but I don't know how to get
Sorry but I am not sure how to ask this question but I am
Sorry if this question seems stupid, but it's stumped me for a couple days,
Sorry if this is a stupid question, but is there an easy way to
Sorry to post another question that is similar to the question that I posted
Sorry if this is an elementary question but I've just started to consider whether
I'm sorry in advance if this question is flawed. I'm pretty new to databases(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.