So I did it this far, I'm not really sure what to do after this.
How do I do the operation of two integers that gives you the results?
I'm supposed to write a program that:
Asks the user for an integer
Asks the user for one of '+', '-', '*', or '/' (as a character)
Asks the user for another integer
Performs the given operation on the two integers, and prints out the result of
Please enter an integer: 4
Please enter an operation (+, - , *, /): *
Please enter another integer: 5
4 * 5 = 20
[code]
#include <iostream>
using namespace std;
int main() {
int x;
int c;
int d;
char e;
cout << "Please enter an integer: ";
cin >> x;
cout << "Please enter one of operation (+, - , *, /): *";
cin >> e;
cout << "Please enter a second integer";
cin >> c;
if (e == '+')
cout << x << e << c << " = " << x + c;
else if (e == '-')
cout << x << e << c << " =" << x +d;
int main() {
int x;
int a;
int b;
int c;
int d;
char e;
cout << "Please enter an integer: ";
cin >> x;
cout << "Please enter one of operation (+, - , *, /): *";
cin >> e;
cout << "Please enter a second integer";
cin >> c;
if (e == '+')
cout << x << e << a << " = " << x + a;
else if (e == '-')
cout << x << e << b << " = " << x - b;
else if (e == '*')
cout << x << e << c << " = " << x * c;
else if (e == '/')
cout << x << e << d << " = " << x / d;
You appear to be under the impression that the variable used for the second integer changes, it does not. Only declare x, e and c and try something like:
1 2 3 4 5 6 7 8
if (e == '+')
cout << x << e << c << " = " << x + c;
elseif (e == '-')
cout << x << e << c << " = " << x - c;
elseif (e == '*')
cout << x << e << c << " = " << x * c;
elseif (e == '/')
cout << x << e << c << " = " << x / c;
You may also want to give the variables more appropriate names, it'll make it easier in the long run.