0
How to assign a math char into an Array ?
to creat a number game.
3 ответов
0
Thank you .It is in C++.I want to pass (+,*,/,-)as an assiged array so 2 b[0]-->+ 3 = 5.Maybe it is wrong approch but i think I need to overload a char or bulit an object in C++. I am working on it.I will update .again thank you so much.
0
Answered by https://www.youtube.com/watch?v=tT8ICXAO_-4
and it was about using Vectors followed by the code as follows:
string Calc = " ";
vector<string>vecCalc;
cout << "enter calcualtion ex. 5 + 6\n";
getline(cin, Calc);
stringstream ss(Calc);
string indivWords;
char space = ' ';
while (getline(ss, indivWords, space))
{
vecCalc.push_back(indivWords);
}
num1 =stod(vecCalc[0]);
num2 =stod (vecCalc[2]);
string opration = vecCalc[1];
if (opration == "+")
cout << fixed << setprecision(2) << fixed << num1 + num2 << endl;
else if (opration == "-")
cout << fixed << setprecision(2) << fixed << num1-num2<< endl;
else if (opration == "/")
cout << fixed << setprecision(2) << fixed << num1 / num2 << endl;
else if (opration == "*")
cout << fixed << setprecision(2) << fixed << num1 * num2 << endl;
else
cout << "Dude print somthing logical" << endl;