【发布时间】:2020-11-11 03:52:59
【问题描述】:
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
using namespace std;
struct Calculations //structure to hold the numbers and operators from 'equation'
{
double num1;
char operators;
double num2;
double answer;
};
Calculations myCalculationArray[SIZE]; // the array of calculations
int main()
{
while (i = 0; i <= 5; i++;)
{
cout << "Enter equation: \n";
getline(cin, equation);
cout << equation;
}
}
好吧,所以我正在尝试构建一个计算器,用户输入一个像“22/2”这样的等式,然后让它像分配第一个数字给 num1 = '22' 和 operator =' / ' 给运算符等等
【问题讨论】:
-
是作业吗?可以询问您需要的更具体的部分,例如:“这个解决方案的部分应该是什么?”但目前听起来像是“你能帮我解决这个问题吗”。
-
是的,这是作业,我不明白如何解析字符串来给我各个部分。
-
while应替换为for和;在i++之后不需要 -
@sravs 为什么我应该使用“for”而不是“while”
-
您已经编写了三个部分(初始化;条件检查;更新),如
for。while只进行部分条件检查,如while(i <= 5)
标签: c++ string data-structures