回忆炭功能
我是编程的新手,并且在C中进行了一个简单的机器人,该机器人具有一个计算器功能。我在此代码中遇到了一些麻烦:
char operation = get_char("Insert the mathematical operation: ");
float x = get_float("X: ");
float y = get_float("Y: ");
if (operation == 43)
{
float result = (x + y);
int rresult = round(result);
printf("X + Y = %i\n", rresult);
string confirmation = get_string("Need to do something more? ");
if (strcmp(confirmation, "Y") == 0)
{
return operation;
}
如您所见,该计算器向用户询问char(*, /, +或 - [它在代码的其他部分中定义的所有内容,我不会发布它在这里简要介绍]定义数学操作,然后在进行计算并打印结果后,询问用户是否要进行更多计算。一件代码,要求炭和浮子,并做所有事情。 另外,我正在使用CS50 IDE。
I'm very new to programming, and I'm doing a simple bot in C, that has a calculator function. I'm having some trouble in this piece of code:
char operation = get_char("Insert the mathematical operation: ");
float x = get_float("X: ");
float y = get_float("Y: ");
if (operation == 43)
{
float result = (x + y);
int rresult = round(result);
printf("X + Y = %i\n", rresult);
string confirmation = get_string("Need to do something more? ");
if (strcmp(confirmation, "Y") == 0)
{
return operation;
}
As you can see, this calculator ask the user for a char (*, /, + or - [its everything defined in the other parts of the code, I will not post it here just to be brief] that defines the math operation and then, after doing the calculation and printing the result, asks the user if he wants to do more calculations. If the answer is "Y" (yes), I want to restart this piece of code, asking for the char and the floats, and doing everything. I want to know the simplest way to do this, without making the code looks bad designed.
Also, I'm using CS50 IDE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有CS50,因此,C。
I don't have CS50, therefore, plain C. The construct you might want to use is a do-while loop.