Hi Tyler, I slightly tweaked your code, it looks like this now:
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
|
#include <iostream>
using namespace std;
float FirstNumber = 0.0;
float SecondNumber = 0.0;
char MathSymbol;
float MultResult = FirstNumber * SecondNumber;
float DivResult = FirstNumber / SecondNumber;
float AddResult = FirstNumber + SecondNumber;
float SubResult = FirstNumber - SecondNumber;
void MultiplyNumbers();
void AddNumbers();
void SubtractNumbers();
void DivideNumbers();
int main()
{
cout << "Enter first number: ";
cin >> FirstNumber;
cout << "Enter operation symbol: ";
cin >> MathSymbol;
cout << "Enter second number: ";
cin >> SecondNumber;
if (MathSymbol == 'x' || MathSymbol == '*')
{
MultiplyNumbers();
}
if (MathSymbol == '+')
{
AddNumbers();
}
if (MathSymbol == '-')
{
SubtractNumbers();
}
if (MathSymbol == '/')
{
DivideNumbers();
}
return 0;
}
void MultiplyNumbers()
{
cout << FirstNumber << " x " << SecondNumber;
float MultResult = FirstNumber * SecondNumber;
cout << "= " << MultResult << endl;
}
void AddNumbers()
{
cout << FirstNumber << " + " << SecondNumber;
float AddResult = FirstNumber + SecondNumber;
cout << "= " << AddResult << endl;
}
void SubtractNumbers()
{
cout << FirstNumber << " - " << SecondNumber;
float SubResult = FirstNumber - SecondNumber;
cout << "= " << SubResult << endl;
}
void DivideNumbers()
{
cout << FirstNumber << " / " << SecondNumber;
float DivResult = FirstNumber / SecondNumber;
cout << "= " << DivResult << endl;
}
|
The differences are that in a cout << statement, I changed "multiplication"
to "operation" signifying to a user that you can do more then multiplication.
I also the if condition that checked to see if it multiplication.
Originally, it checked to see if the character was 'x' no it also checks for '*'
I did this by using || its the OR operator.
the problem i think was giving you an error was your call to the function.
You included the function type
void DivideNumbers ();
When your calling a function, you do not need to include its type, only its name, so it would be
DivideNumbers ();
It was like that for all of them, so I changed that. hope it works :)
Oh ya, funny thing I saw on YouTube:
http://www.youtube.com/watch?v=wSReSGe200A