C++ C++;布尔语句错误(我认为)

C++ C++;布尔语句错误(我认为),c++,function,boolean,C++,Function,Boolean,这个程序应该要求一个整数,如果你想加或减,然后是另一个整数,然后做数学运算,但是它声明减法和加法都是错误的输入,我认为我的布尔值有错误。感谢您的帮助 /*********************************************************** Program Name: Simple Math Calculator Program Author: Kyle NoCompile Date Creat

这个程序应该要求一个整数,如果你想加或减,然后是另一个整数,然后做数学运算,但是它声明减法和加法都是错误的输入,我认为我的布尔值有错误。感谢您的帮助

            /***********************************************************
        Program Name: Simple Math Calculator
        Program Author: Kyle NoCompile
        Date Created: 9/12/16
        Program Description:
            This program performs simple arithmetic calculations.
            The user enters numbers and the math operation to
            perform on those numbers. The program will then display
            the result of the operation.

        Modified Date:
        Modified Description:
        ***********************************************************/

        #include <iostream>
        using namespace std;

        // Function prototypes:
        void showWelcome();
        int getUserIntegerInput();
        char getMathChoice();
        int getInteger(bool);
        bool validateMathChoice(char choice);
        int doAddition(int int1, int int2);
        int doSubtraction(int int1, int int2);
        int doMath(int firstInt, int secondInt, char mathFunc);
        int showResult();


        // This is the main function (where the program begins)
        int main()
        {
            // Variables to hold local data
            int firstNum;
            int secondNum;
            int mathChoice;
            int result;

            // Call the showWelcome() function
            void showWelcome();

            // Call the getInteger() function (for the first integer)
            // and store the result in the "firstNum" variable
            firstNum = getInteger(true);


            // Call the getMathChoice() function and store result in "mathChoice" variable
            mathChoice = getMathChoice();

            // Call validateMathChoice() function, passing it the user's math choice
            // and using the return value to decide what to do next
            if (validateMathChoice() = true)
            {
                // Call the getInteger() function (for the second and subsequent integers)
                // and store the result in the "secondNum" variable
                secondNum = getInteger(false);

                // Call the doMath() function and pass it all of the user input
                // and store the return value in the "result" variable.
                int result = doMath(firstNum,secondNum,mathChoice);

                // Call the showResult() function to show the result
                int showResult(int result);
            }
            else
            {
                // If the user chose an invalid math function...
                cout<<"Not a valid math choice"<<endl;
            }

            return 0;
        }


        // This function shows a nice welcome message
        void showWelcome()
        {
            cout<<"******************************************"<<endl;
            cout<<"Welcome to the simple calculator program!"<<endl;
            cout<<"This program will do simple addition and"<<endl;
            cout<<"subtraction. Math is fun, so enjoy!"<<endl;
            cout<<"******************************************"<<endl;
        }

        // This function gets integer input from the user
        int getUserIntegerInput()
        {
            int input;
            cin>>input;
            return input;
        }

        // This function asks the user for a math function
        // and returns the user's input
        char getMathChoice()
        {
            char choice;
            cout<<endl<<"Please select a math function to perform (\"+\" = Addition, \"-\" = Subtraction): ";
            cin>>choice;
            return choice;
        }

        // this function asks the user for either the first integer
        // or the second and returns the user's input
        int getInteger(bool firstNum)
        {
            cout<<endl<<"Please enter the ";

            // if the "firstNumber" variable is true, then this
            // is the first number being collected
            if (firstNum)
            {
                cout<<"first ";
            }
            // Otherwise, it's the second number being collected
            else
            {
                cout<<"second ";
            }

            cout<<"integer: ";

            // Call the getUserIntegerInput() function and return the return value from it
            return getUserIntegerInput();
        }



        // This function validates the user's match function choice
        // by returning a true for valid, and a false for invalid
        bool validateMathChoice(char choice)
        {
            if (choice == '+' || choice == '-')
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        // This function adds two integers
        int doAddition(int firstInt,int secondInt)
        {
            return firstInt + secondInt;
        };

        // This function subtracts the second integer
        // parameter from the first integer parameter
        int doSubtraction(int firstInt, int secondInt)
        {
            return firstInt - secondInt;
        };


        // This function determines the result of the math
        // operation requested by the user
        int doMath(int firstInt, int secondInt, char mathFunc)
        {
            // Initialize result to zero (0)
            int result = 0;

            // If the math function is a "+", then call the
            // doAddition() function and store the return
            // value in the "result" variable
            if (mathFunc = '+')
            {
                result = doAddition(firstInt, secondInt);
                return result;
            }
            // If the math function is a "-", then call the
            // doSubtraction() function and store the return
            // value in the "result" variable
            else (mathFunc = '-');
            {
                result = doSubtraction(firstInt, secondInt);
                return result;
            }

            return result;
        }

        // This function displays the result of a math operation
        int showResult(int result)
        {
            cout<<endl<<"The result is "<<result<<endl;
        }
/***********************************************************
程序名称:简单数学计算器
节目作者:Kyle NoCompile
创建日期:2016年9月12日
程序说明:
这个程序执行简单的算术计算。
用户输入数字和数学运算以
在这些数字上执行。然后程序将显示
手术的结果。
修改日期:
修改说明:
***********************************************************/
#包括
使用名称空间std;
//功能原型:
void showWelcome();
int getUserIntegerInput();
char getMathChoice();
int-getInteger(bool);
bool-validateMathChoice(字符选择);
int-doAddition(int-int1,int-int2);
int-DOSUBSTRACTION(int-int1,int-int2);
int-doMath(int-firstInt,int-secondInt,char-mathFunc);
int showResult();
//这是主要功能(程序开始的地方)
int main()
{
//保存本地数据的变量
int firstNum;
int secondNum;
数学选择;
int结果;
//调用showWelcome()函数
void showWelcome();
//调用getInteger()函数(对于第一个整数)
//并将结果存储在“firstNum”变量中
firstNum=getInteger(true);
//调用getMathChoice()函数并将结果存储在“mathChoice”变量中
mathChoice=getMathChoice();
//调用validateMathChoice()函数,将用户的数学选择传递给它
//并使用返回值来决定下一步要做什么
if(validateMathChoice()=true)
{
//调用getInteger()函数(用于第二个和后续整数)
//并将结果存储在“secondNum”变量中
secondNum=getInteger(false);
//调用doMath()函数并将所有用户输入传递给它
//并将返回值存储在“result”变量中。
int result=doMath(firstNum、secondNum、mathChoice);
//调用showResult()函数以显示结果
int showResult(int result);
}
其他的
{
//如果用户选择了无效的数学函数。。。

cout==是比较,而不是=。另外,else if(…)not else(…)(可能不需要结尾分号)。将没有向函数传递足够参数的错误放在一边,。==是比较,而不是=。另外,else if(…)not else(…)(可能不需要结尾分号)。将错误放在一边,因为没有向函数传递足够的参数。