mini calculator

Hi guys I am real new to coding and am having a lot of trouble writing a mini calculator program. I have written codes in the past but am having trouble writing this program as simply as possible. I am having trouble with what to write in my input and process sections. I would really appreciate it if someone could possible show me the right way to write this program. Thank you!!

Create a mini calculator program that will allow the user to enter two integers (operand 1 and operand 2), the program will calculate the sum, difference ,product, whole number quotient, remainder, the real number quotient, and the square root of operand1. The program should also calculate the value of operand2 raised to the power of 4.
Does you want all of that output at the same time or have the choice of selecting an operand beforehand?
OP: please delete your other 2 posts on same topic under the 'General' section of this forum
Last edited on
what trouble are you having, what do you have so far?

some hints of things you might not have gotten yet...
% is effectively remainder.

so 5%4 is 1. 4%4 is 0. 8 %4 is 0.

/ is the "quotient" in your terms.

double d = (double)(intva1)/intval2; //force it to be a real number

sqrt(x); //built in square root function.
pow (x,4); //built in power function. these things are in <cmath>

I want all of that output at the same time. I had already made one selecting an operand before hand need it all at the same time
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/210733/
i really just need help with what i need to put into my input section and how to properly declare my variables
Maybe just declare two doubles, name them operand1 and operand2 and make them equal 0.

have the user input both variables.

1
2
3
4
double operand1 = 0;
double operand2 = 0;

cin >> operand1 >> operand2;


Something like this maybe?
that works. Then how would I declare the input values? do i have to do that when i run it?
Right.

So "cin" is user input.

If I wrote the code like this:
1
2
3
4
5
6
7
cout << "Operand1: ";
cin >> operand1;
cout << "" << endl;

cout << "Operand2: ";
cin >> operand2;
cout << "" << endl;

The user will input operand1 and operand2 and assign it with whatever input is put in.
got it! thank you very much!
You're welcome!

This is how I would write it:
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <math.h>

using namespace std;

// Function Prototypes
double addNum(int, int);
double diffNum(int, int);
double productNum(int, int);
double quoNum(int, int);
double remainNum(int, int);
double sqRoot(int);
double expFour(int);
void displayData();
void displayQuestion();


// Global Variables
int operand1 = 0;
int operand2 = 0;

int main()
{
	displayQuestion(); // Function that asks for the operands

	displayData(); // Function that displays all of the calculations

	return 0; // Ends the program
}

// Adds operands
double addNum(int fn_operand1, int fn_operand2)
{
	int fn_sum = fn_operand1 + fn_operand2;
	return fn_sum;
}

// Subtracts operands
double diffNum(int fn_operand1, int fn_operand2)
{
	int fn_diff = fn_operand1 - fn_operand2;
	return fn_diff;
}

// Multiplys operands
double productNum(int fn_operand1, int fn_operand2)
{
	int fn_product = fn_operand1 * fn_operand2;
	return fn_product;
}

// Divides operands
double quoNum(int fn_operand1, int fn_operand2)
{
	int fn_quo = fn_operand1 / fn_operand2;
	return fn_quo;
}

// Remainder of operands
double remainNum(int fn_operand1, int fn_operand2)
{
	int fn_remain = fn_operand1 % fn_operand2;
	return fn_remain;
}

// Square Root of operand1
double sqRoot(int fn_operand1)
{
	double fn_sqRoot = sqrt(fn_operand1);
	return fn_sqRoot;
}

// Operand2 to the power of four
double expFour(int fn_operand2)
{
	double fn_expFour = pow(fn_operand2, 4);
	return fn_expFour;
}

// Displays operand questions
void displayQuestion()
{
	cout << "Enter two integers to work with: ";
	cout << "" << endl;
	cout << "Operand1: ";
	cin >> operand1;
	cout << "" << endl;

	cout << "Operand2: ";
	cin >> operand2;
	cout << "" << endl;
}

// Displays all answers
void displayData()
{
	cout << "Sum: " << addNum(operand1, operand2) << endl;
	cout << "" << endl;

	cout << "Difference: " << diffNum(operand1, operand2) << endl;
	cout << "" << endl;

	cout << "Product: " << productNum(operand1, operand2) << endl;
	cout << "" << endl;

	cout << "Quotient: " << quoNum(operand1, operand2) << endl;
	cout << "" << endl;

	cout << "Remainder: " << remainNum(operand1, operand2) << endl;
	cout << "" << endl;

	cout << "Square Root of Operand1: " << sqRoot(operand1) << endl;
	cout << "" << endl;

	cout << "Operand2 ^ 4: " << expFour(operand2) << endl;
	cout << "" << endl;
}
Last edited on
Topic archived. No new replies allowed.