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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:42:31+00:00 2026-06-01T07:42:31+00:00

Hello guys look to my code I’m trying to make a program which asks

  • 0

Hello guys look to my code I’m trying to make a program which asks you to enter the first value by grams And the second value is kilograms and then convert kilograms to grams by an overloaded + operator but it doesn’t work why

#include <iostream>
using namespace std;
class ADD{
private:
    int Fval;
    int Sval;
public:
    ADD(){
            cout << "WELCOME TO OUR PROGRAM"<<endl<<"PLEASE ENTER THE FIRST VALUE BY GRAMS :";
            cin >> Fval;
            cout << "PLEASE ENTER THE SECOND VALUE BY KILOGRAMS :"; cin >> Sval;
        }
    ADD operator+(ADD& add){
        add.Sval *= 1000;
        return add;
    }
    int plus(){
        return Fval+Sval;
    }
};
int main(){
    ADD a1;
    cout << "THE TOTAL VALUE = " << a1.plus() << " GRAMS";
}

No Effect look to the output

WELCOME TO OUR PROGRAM
PLEASE ENTER THE FIRST VALUE BY GRAMS :2
PLEASE ENTER THE SECOND VALUE BY KILOGRAMS :3
THE TOTAL VALUE = 5 GRAMS

That means the + operator doesn’t multiply 3 by 1000
Why??

  • 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-01T07:42:31+00:00Added an answer on June 1, 2026 at 7:42 am

    That’s because you’re not calling operator +.

    You’re calling ADD::plus():

    int plus(){
        return Fval+Sval;
    }
    

    Fval and Sval are integers, which you’re adding up. It’s as simple as that.

    EDIT:

    Your code is fishy.

    ADD operator+(ADD& add){
        add.Sval *= 1000;
        return add;
    }
    

    Multiplication inside operator +? Really? Also, not that you’re modifying the parameter, which you shouldn’t. It’s not intuitive. If you really must do this:

    ADD operator+(const ADD& add){
        ADD ret;
        ret.Sval = add.Sval * 1000;
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys! I have been trying to create a if/else statement code in jQuery
What I've tried Hello Guys, I first created a database which I've filled with
Hello guys first of all apologize for asking such a simple and yet redundant
hello guys I am trying to extract all the anchor links from aol but
Hello guys, I have been trying to implement the DSUM function but failed to
Hello Guys I am trying to figure out why i am gettings this error
Hello guys. I trying set EditText to input only numbers and point ( .
Hello guys Im using advance notification manager this is the code Notification note =
Hello guys i'm having one hell of a time trying to parse an xml
* Hello Guys..! * Normally a java program needs main() function to execute the

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.