Simple Calc

Write a simple calculator program that allows input of two integer operands and outputs the result of all five arithmetic operations (+, -, *, / , & %). Modularize into “at-least” the following functions:�
getData
getInteger
processData
displayData
�Can somebody make this program I have no idea how to.
This is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find derivative of function without knowledge in arithmetic, you cannot do more complex tasks in programming without clear understanding of basics.
I am not sure if I have even approached this problem correctly. I have done the very beginning but have no idea where to go from there. Not sure how to divide the work into the functions getInteger, processData, and displayData.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37




#include <iostream>
using namespace std;

int getData(int x, int y); //function prototypes
int getInteger();
void processData();
void displayData();

int main()
{
int x = 0;
int y = 0;
int sum = 0;
int diff = 0;
int prod = 0;
int quot = 0;
int mod = 0;
cout<<"Please enter an integer: ";
cin>>x;
cout<<"Please enter an integer: ";
cin>>y;

getData(x,y); //call function
return 0;
}
int getData(int x, int y)
{
int sum, diff, prod, quot, mod;

sum = (x+y);
diff = (x-y);
prod = (x*y);
quot = (x/y);
mod = (x%y);
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>

// accept an integer from stdin and return it
int get_integer()
{
    int number ;
    std::cin >> number ;
    return number ;
}

// get the input data for the program
// (two integers on which calculations are to be performed)
// arguments are passed by reference, we want to set values into them.
void get_data( int& x, int& y )
{
    std::cout << "enter the first integer: " ;
    x = get_integer() ;

    std::cout << "enter the second integer: " ;
    y = get_integer() ;
}

int main()
{
    int x = 0 ;
    int y = 0 ;

    get_data( x, y ) ; // get the numbers entered by the user into x and y

    std::cout << "x == " << x << " and y == " << y << '\n' ;

    // TO DO: rest of program
}


Take it up from there.
#include <iostream>
#include <cmath>

// accept an integer from stdin and return it
int get_integer()
{
int number ;
std::cin >> number ;
return number ;
}

// get the input data for the program
// (two integers on which calculations are to be performed)
// arguments are passed by reference, we want to set values into them.
void get_data( int& x, int& y )
{
std::cout << "enter the first integer: " ;
x = get_integer() ;

std::cout << "enter the second integer: " ;
y = get_integer() ;
}

int main()
{
int x = 0 ;
int y = 0 ;

get_data( x, y ) ; // get the numbers entered by the user into x and y

std::cout << "x = " << x << " and y = " << y << '\n' ;


}
void process_data (int x, int y)
{
int sum = (x+y);
int diff = (x-y);
int prod = (x*y);
int quot = (x/y);
int remain = (x%y);

}
void display_data (int x, int y, int sum, int diff, int prod, int quot, int remain)
{
std::cout << x << "+" << y << "=" << sum;
std::cout << x << "-" << y << "=" << diff;
std::cout << x << "*" << y << "=" << prod;
std::cout << x << "/" << y << "=" << quot;
std::cout << x << "%" << y << "=" << remain;

}
i dont know why this isnt working. only shows what x and y are equal too
Topic archived. No new replies allowed.