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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:26:46+00:00 2026-06-13T03:26:46+00:00

This code is adding two integers with the addition operation including the carry process,

  • 0

This code is adding two integers with the addition operation including the carry process,
I am having an error here but I don’t know what is it exactly here !
the aim of the program is to make c++ take a big number “bigger than size of int” and make addition process .. I really need a help !
Thank you !

#include "stdafx.h"
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

class BigDecimalInt
{
    protected:
    int num1;
    public:
    string s1;

    string getstring()
    {
        return s1;
    }
    void setstring(string s2)
    {
        s1=s2;
    }
    BigDecimalInt (string decStr){s1=decStr;}
    BigDecimalInt (int decInt); // Initialize from integer
    BigDecimalInt operator+ ();
    BigDecimalInt operator- (BigDecimalInt anotherDec);
};

BigDecimalInt operator+ (BigDecimalInt firstDec,BigDecimalInt secDec)
{
    int size,diff,carry=0,x,y,z,counter=0;
    BigDecimalInt temp("");
    string c1,c2,result,smaller,bigger;
    c1=firstDec.getstring();
    c2=secDec.getstring();
    if(c1.length()<c2.length())
        {
            smaller = c1;
            bigger = c2;
        }
    else
       {
           smaller = c2;
           bigger = c1;
       }
    diff = bigger.length()-smaller.length();
    size = smaller.length();
    for(int i=size-1;i>=0;i--)
        {
            y = int(bigger[i+diff]);
            y-=48;
            x = int(smaller[i]);
                x-=48;
            z = x+y+carry;
            if(z<=9)
            {
                result+=char(z+48);
                carry = 0;
            }
            else
            {
                result+=char(z+38);
                carry = 1;
            }
        }
    while((carry==1)&&(counter<bigger.length()))
    {
        counter = size;
        x = int(bigger[counter])-48+carry;
        if(x<=9)
            {
                result+=char(x+48);
                carry = 0;
            }
        else
        {
            result+=char(x+38);
            carry = 1;
        }
        counter++;
    }
    if(counter==bigger.length())
        {
            if(carry==1)
            result+=char(49);
        }
    else
        for(int o=counter;o>=0;o++)
            result+=bigger[o];

    temp.s1=result;

    return temp;
}
int _tmain(int argc, _TCHAR* argv[])
{
     string k1,k2;

    cout<<"Enter first num : \n";
    cin>>k1;
    BigDecimalInt c1(k1);
    cout<<"Enter second num : \n";
    cin>>k2;
    BigDecimalInt c2(k2);

    BigDecimalInt c3("");

    c3=c1+c2;
    cout<<c3.s1;
    system("pause");
    return 0;
}
  • 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-13T03:26:47+00:00Added an answer on June 13, 2026 at 3:26 am

    This for loop stands out as different

    for(int o=counter;o>=0;o++)
    

    All the others are counting down to zero, but this seems to be counting up.

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

Sidebar

Related Questions

I want to write simple C++ code for adding two integers (in a command
iam adding a contact to the device using this code long Contact_Id = 100;
HI, I have this code for extracting the href and adding it to a
1. Problem I am adding a shoutcast radio to website (appeding this code to
This code below allows me to find the word error in all my files
This code gives me this error:Cannot implicitly convert type ArrayList[] to ArrayList[][] at this
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
I'm adding new rows to a table dynamically, with this code: tbody = document.getElementById('tbody');
I am trying to create a multidimensional arraylist. but it is not adding this

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.