我用C++;,但我的要求是;“计算器类型”;循环两次。有人能帮我指出我的错误吗? 我刚开始学C++,最近刚学的时候,我想我会尝试做一些事情来看看我的研究结果。我计划制作一个具有多种功能的计算器,(希望如此),最终可能会包括绘图方程和更难的计算等功能

我用C++;,但我的要求是;“计算器类型”;循环两次。有人能帮我指出我的错误吗? 我刚开始学C++,最近刚学的时候,我想我会尝试做一些事情来看看我的研究结果。我计划制作一个具有多种功能的计算器,(希望如此),最终可能会包括绘图方程和更难的计算等功能,c++,calculator,C++,Calculator,这是我的密码: #include "stdafx.h" #include <math.h> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #include <string> #include <iostream> using namespace std; //CALCULATOR //Function

这是我的密码:

#include "stdafx.h"
#include <math.h>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iomanip>
#include <string>
#include <iostream>

using namespace std;



//CALCULATOR



//Functions
int chooseCal();
float getOp();
float getOpAd();
float userInput();
float normCal(float x, float ops, float y);



float getOp() //ask for operator input
{
    cout << "Enter an operator: " << endl;
    cout << "1. + (Addition) \n";
    cout << "2. - (Subtraction) \n";
    cout << "3. * (Multiplication) \n";
    cout << "4. / (Division) \n";
    cout << "5. ^ (Indices) \n";
    cout << "6. -^ (Root) \n";
    cout << "7. ! (Factorial) \n";

    float ops;
    cin >> ops;

    return ops;
}

float getOpAd()//ask for operator (Advanced Cal)
{
    cout << "Enter an operator: " << endl;
    cout << "1. Denery ==> Binary" << endl;
    cout << "2. Binary ==> Denery" << endl;
    cout << "3. Denery ==> Hexadecimal" << endl;
    cout << "4. Hexadecimal ==> Denery" << endl;

    float ops;
    cin >> ops;

    return ops;
}

int chooseCal()
{
    cout << "Which calculator would you like to use? " << endl;
    cout << "1. Normal \n";
    cout << "2. Computational \n";

    int chooseC;
    cin >> chooseC;

    return chooseC;
}

float userInput() //ask for number input
{
    cout << "Enter a number: ";

    float userInput;
    cin >> userInput;

    return userInput;
}

//Calculators
float normCal(float x, float ops, float y) //Basic
{
    if (ops == 1)
        return x + y;
    if (ops == 2)
        return x - y;
    if (ops == 3)
        return x * y;
    if (ops == 4)
        return x / y;
    if (ops == 5)
        return pow(x, y);
    if (ops == 6)
        return pow(x, 1 / y);
}


//prints result
void result(float result)
{
    cout << "= " << result << endl;
}



//main()
int main()
{
    int chooseC = chooseCal();

    float ops;
    if (chooseCal() == 1)
        ops = getOp();
    else
        ops = getOpAd();

    float input1 = userInput();
    float input2 = userInput();

    float results = normCal(input1, ops, input2);
    result(results);

    return 0;
}
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
//计算器
//功能
int chooseCal();
float getOp();
浮点getOpAd();
float userInput();
浮动标准(浮动x、浮动操作、浮动y);
float getOp()//请求操作员输入
{

cout对
chooseCal()
函数的第一次调用在以下语句中:

int chooseC = chooseCal();
if (chooseCal() == 1)
第二个在以下
if
语句中:

int chooseC = chooseCal();
if (chooseCal() == 1)
函数在条件中使用并不意味着它不会被执行。它会被执行。在这里,您可能是指:

if (chooseC == 1)

您在主函数中调用了多少次
chooseCal()
?为什么您接受
op
作为
float
float ops
)?它应该是
enum
char
或实际上不是floatif(chooseCal()==1)应该被chooseCal替换为chooseCal对于几乎所有的菜单,您要求整数输入,并将其存储在一个
float
中。为什么?可能它要求它两次,因为您两次调用它?
int choosece=chooseCal()
if(chooseCal()==1)
非常感谢!这是我不知道的