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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:00:59+00:00 2026-06-11T19:00:59+00:00

I am building a simple calculator as a learning exercise and I have stumbled

  • 0

I am building a simple calculator as a learning exercise and I have stumbled – I get the user input for the first number, but it fails to store the int for the second input – do I need to create objects? I assume this is an obvious problem…

//Simple calculator to work out the sum of two numbers (using addition)

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    cout << "Enter the first int: \n";
    int input1 = std::cin.get();

    cout << "Enter the second int: \n";
    int input2 = std::cin.get();


    cout << "The sum of these numbers is: " << input1 + input2;
    cout << "\n";


    system("PAUSE");
    return EXIT_SUCCESS;
}
  • 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-11T19:01:00+00:00Added an answer on June 11, 2026 at 7:01 pm

    cin.get() only retrieves one character of input. Why not use

    int input1, input2;
    cout << "Enter the first int: \n";
    cin >> input1;
    cout << "Enter the second int: \n";
    cin >> input2;
    

    Using std::cin this way (with operator>>) also takes care of any surplus newline or space characters a user entered.

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

Sidebar

Related Questions

I am building a simple Calculator application. I'm also learning how to apply the
building a simple calculator here to get my feet wet with iOS dev. I
I'm building a simple availability calendar with PHP and MySQL. I have a table
I am building a simple echo server for the purposes of learning the fundamentals
I'm building a very simple voiceXML app to allow people to make recordings. But
I was building a simple web based calculator which takes equations from a HTML
Building a simple login page. If the user types in a password and password
I'm building simple query builder, and I have two questions: Is it possible to
Am new to Android, and am building a simple calculator app. I want to
Say, we are using EF Code First and we have this simple model: using

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.