Thank for all the help, I cant use char and [], since its not part of session I'm on.
@Ganado, thanks I fixed the int part. I dont understand tho, the return types on line 3, 14, and 25 should be corrected due to return value; and same for other. Unless I am wrong?
@jonnin the cout << value1 << tbl where do I put and which will it refer to? Do I need to create new char inside int main? such as char tb, tho [], I don't know what it does.
But from all the suggest, It gave me some idea. It work but not as I intend. I got the answer such as 5 + 5 in the end, but the random addition information are added since it called twice.
Any idea of modify it without using the extra term which I haven't yet learned?
Thank again
ps. I stopped the adjusting on line 30, since keep going seem pointless as it doesn't get result as I intend. But its the idea I that got the part I wanted to work.
pss. I forget to say, this is my own personal testing. I already passed first quiz. I wanted to make this more convenient.
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
|
#include <iostream>
int getANumber()
{
std::cout << "Put your number here: " << std::endl;
int value;
std::cin >> value;
return value;
}
int getOperator()
{
std::cout << "Pick a number: (1 = +, 2 = -, 3 = *, 4 = / " << std::endl;
int op;
std::cin >> op;
return op;
}
int storeNumber(int x, int op, int y)
{
if(op == 1)
op = x + y;
std::cout << x << op << "+" << y << std::endl;
return x, op, y;
if(op == 2)
op = x - y;
if(op == 3)
op = x * y;
if(op == 4)
op = x / y;
}
void getResult(int result)
{
std::cout << "Your answer is " << result << std::endl;
}
int main()
{
int value1 = getANumber();
std::cout << "Your first number is: " << value1 << std::endl;
std::cout << std::endl;
int op = getOperator();
std::cout << "So far: (" << value1 << ", " << op << std::endl;
std::cout << std::endl;
int value2 = getANumber();
std::cout << "Your second number is: " << value2 << std::endl;
std::cout << std::endl;
std::cout << "Now...: (" << value1 << ", " << op << ", " << value2 << ")" << std::endl;
int result = storeNumber(value1, op, value2);
std::cout << std::endl;
getResult(result);
return 0;
}
|