How do you pass user input from main to other classes?

Valskarx
#include <iostream>
#include "multiplication.h"
#include "subtraction.h"
using namespace std;

int main() {

    multiplication out;
    subtraction out2;

    int x, y, z;
    int product;
    int difference;

    cout << "Enter two numbers to multiply by: ";
    cin >> x;
    cin >> y; 
    product = out.mult();
    cout << "the product is: " << product;

    cout << "Now enter a number to subtract the product by: ";
    cin >> z;
    difference = out2.sub();
    cout << "the difference is: " << difference;
}

    #pragma once

class multiplication
{
public:

    int mult();

};

#include <iostream>
using namespace std;
#include "multiplication.h"

int multiplication::mult(int x, int y) {

    return x * y;
}

    #pragma once
class subtraction
{
public:

    int sub();
};

#include <iostream>
using namespace std;
#include "subtraction.h"

int subtraction::sub(int product, int z) {

    return product - z;
}

I need to pass the user input variables from main to mult and the user input z and product from main to sub. I tried passing them as args in the functions I've created, but they are not accessed.

Edit: I added multiplication.h and subtraction.h In them I just have the call to the function declarations for the class.

Michael Crippa

You should pass them to the function call as arguments

 difference = out2.sub(x, y);

In the .h files you should define them with arguments

class subtraction
{
    public:    
    int sub(int x, int y);
};

Function overloading

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I get user input from separate classes

How do you print a function from user input?

C# Pass user input to method, and output result (from the main)?

How do you pass arguments from command line to main in Flutter/Dart?

How can you pass user input from a text box into a function securely, and then output to DOM?

How to do with that if I want to pass the data from the input, and also want user can not edit the id input?

Bixby - Pass user input from once action to other

How to get user input and pass it as an argument in function inside classes in python

Vuejs: how do you pass class(classes) to template?

How Do You Pass PropertyChanged Events Between Classes?

How do you delete certain strings from a textfile based on user input in c

how do you get the first letter of a name from user input and put it into a if loop?

ANSI C: How do you ingest input from user and then print it in reverse?

How do you store data values into an array from user input in a dialog box?

How do you execute a function while Python 3 is taking input from the user?

How do you read umlaut from user-given input for a Java application?

How do you get the user data from a HTML input (text) created using createElement()?

How do you pass TCP connection objects to other Go modules?

How do you pass variables to other JS modules with Fetch API?

How do I access a user input from grunt-prompt in other tasks

How to pass an input from c++ function to the main function

Java, value changed in main via methods, how to pass this value correctly to other classes

How to take user input from main method to another class and method?

how do you round up a double user input value in java?

How do you print user input to csv files on multiple lines?

How do you let user input a lengthy string into a variable?

How do you print different things depending the user input?

How do you print a random result with user input in labels?

How do you ask for user input in list comprehension?