I'm stuck because I can make the calculator just find but the user will have to press enter after every number, what is s solution to this?
#include <iostream>
#include <string>
using namespace std;
int a = 1, b, c;
string symbol;
int multiplyFunction();
int main()
{
// This is the problem, the user has to press enter after everything, making it a tedious process.
cin >> a;
cin >> symbol;
cin >> b;
if (symbol == "*");
{
cout << multiplyFunction();
}
system("pause");
return 0;
}
// Function to multiply, followed by function to divide, add, etc.
int multiplyFunction()
{
c = a * b;
return c;
}
You don't have to press enter every time. cin uses the space character as a delimiter. So just seperate your entries with a space. Also you need to prompt the user, so they know what to input.
Thank you, that's really helpful information, but now I have this problem of the program performing all of the functions
#include <iostream>
#include <string>
using namespace std;
int a, b, c, w = 1;
string symbol;
int multiplyFunction();
int divideFunction();
int addFunction();
int substractFunction();
int main() {
while (w = 1)
{
// The program runs all of this code so I get 5 + 5 will get 10125 (5 + 5, 5 / 5, and 5 * 5
cin >> a;
cin >> symbol;
cin >> b;
if (symbol == "+");
{
cout << addFunction();
return 0;
}
// Function to multiply, followed by function to divide, add, etc.
int substractFunction()
{
c = a + b;
return c;
}
int addFunction()
{
c = a + b;
return c;
}
int divideFunction()
{
c = a / b;
return c;
}
int multiplyFunction()
{
c = a * b;
return c;
}
I don't know what you were having trouble with, but I saw that you had made an error in the substractFuntion(), which I corrected and added to the main. I am on Mac, so you will have to add SysPAUSE again. I also added a user prompt.
#include <iostream>
#include <string>
usingnamespace std;
int a, b, c, w = 1;
string symbol;
int multiplyFunction();
int divideFunction();
int addFunction();
int substractFunction();
int main()
{
cout << "Enter Your Full Equation, Then Press ENTER: ";
while (w == 1)
{
// The program runs all of this code so I get 5 + 5 will get 10125 (5 + 5, 5 / 5, and 5 * 5
cin >> a;
cin >> symbol;
cin >> b;
if (symbol == "+")
{
cout << addFunction();
}
if (symbol == "/")
{
cout << divideFunction();
}
if (symbol == "*")
{
cout << multiplyFunction();
}
if (symbol == "-")
{
cout << substractFunction();
}
}
return 0;
}
// Function to multiply, followed by function to divide, add, etc.
int substractFunction()
{
c = a - b;
return c;
}
int addFunction()
{
c = a + b;
return c;
}
int divideFunction()
{
c = a / b;
return c;
}
int multiplyFunction()
{
c = a * b;
return c;
}
Thank you, did it work fine with you? or am I correct in assuming that because strings are not a native c++ data type that you can't check them in this manner?