gpt4 book ai didi

c++ - 当一个功能完成另一个功能打开时我该怎么办?

转载 作者:太空宇宙 更新时间:2023-11-04 12:59:26 26 4
gpt4 key购买 nike

我有一个问题。我正在尝试制作一个常规计算器和形状的面积和周长查找器。它是一个组合。我没有开始使用形状的面积和周长查找器。这是我的 main.cpp。

 #include <iostream>
#include <string>
#include "AAPO.h" // Its a Header File.

using namespace std;

void Calculators_Operation();

int main()
{
string opera;
cout << "Do you want Arithmetic Calculator or Area and Perimeter Calculator"
<< endl;

cin >> opera;
if (opera == "Arithmetic Calculator" or "arithmetic calculator" or "AC")
{
Calculators_Operation();
}
return 0;
}

这是我的操作选择器。

#include <iostream>
#include <string>
#include "Arithmetic Chooser.h"

using namespace std;

void Calculators_Addition();
void Calculators_Subtraction();
void Calculators_Multiplication();
void Calculators_Division();

void Calculators_Operation()
{
string answera;
cout << "What Operation do you Want?" << endl;
cin >> answera;
if (answera == "Addition" or "addition" or "+");
{
Calculators_Addition();
};
if (answera == "Subtraction" or "subtraction" or "-");
{
Calculators_Subtraction();
};
if (answera == "Multiplication" or "multiplication" or "*" or "x" or "X")
{
Calculators_Multiplication();
};
if (answera == "Division" or "division" or "/")
{
Calculators_Division();
};
return;
}

这是我的 AAPO.h。

#ifndef AAPO_H_INCLUDED
#define AAPO_H_INCLUDED

void Calculators_Operation();

#endif // AAPO_H_INCLUDED

我的补充。

#include <iostream>
#include <string>

using namespace std;

void calculators_Addition_2();
void calculators_Addition_3();
void calculators_Addition_4();
void calculators_Addition_5();

void Calculators_Addition()
{
//ADDITION COMPLETE
string numberadd;
cout << "How much numbers do you want?" << endl;
cin >> numberadd;
if (numberadd == "2")
{
calculators_Addition_2();
return;
};
if (numberadd == "3")
{
calculators_Addition_3();
return;
};
if (numberadd == "4")
{
calculators_Addition_4();
return;
};
if (numberadd == "5")
{
calculators_Addition_5();
return;
}
}

void calculators_Addition_2()
{
int add11;
int add12;
int sum;
cout << "Enter the first number" << endl;
cin >> add11;
cout << "Enter the second number" << endl;
cin >> add12;
sum = add11 + add12;
cout << "The sum of the numbers are " << sum << endl;
return;
}

void calculators_Addition_3()
{
int add13;
int add23;
int add33;
int sum2;
cout << "Enter the First Number" << endl;
cin >> add13;
cout << "Enter the Second Number" << endl;
cin >> add23;
cout << "Enter the Third Number" << endl;
cin >> add33;
sum2 = add13 + add23 + add33;
cout << "The Sum of the Numbers are " << sum2 << endl;
return;
}

void calculators_Addition_4()
{
int add14;
int add24;
int add34;
int add44;
int sum3;
cout << "Enter the First Number" << endl;
cin >> add14;
cout << "Enter the Second Number" << endl;
cin >> add24;
cout << "Enter the Third Number" << endl;
cin >> add34;
cout << "Enter the Fourth Number" << endl;
cin >> add44;
sum3 = add14 + add24 + add34 + add44;
cout << "The Sum of the Numbers are " << sum3 << endl;
return;
}

void calculators_Addition_5()
{
int a15;
int a25;
int a35;
int a45;
int a55;
int sum4;
cout << "Enter the First Number" << endl;
cin >> a15;
cout << "Enter the Second Number" << endl;
cin >> a25;
cout << "Enter the Third Number" << endl;
cin >> a35;
cout << "Enter the Fourth Number" << endl;
cin >> a45;
cout << "Enter the Fifth Number" << endl;
cin >> a55;
sum4 = a15 + a25 + a35 + a45 + a55;
cout << "The Sum of the Numbers are " << sum4 << endl;
return;
}

我的减法。

#include <iostream>

using namespace std;

void Calculators_Subtraction()
{
int subractify;
int subracta;
int differencea;
cout << "Type in the First Number!" << endl;
cin >> subractify;
cout << "Type in the Second Number!" << endl;
cin >> subracta;
differencea = subractify - subracta;
cout << "The Difference is " << differencea << endl;
return;
}

我的乘法。

#include <iostream>
#include <string>

using namespace std;

void Calculators_Multiplication_2();
void Calculators_Multiplication_3();
void Calculators_Multiplication_4();
void Calculators_Multiplication_5();

void Calculators_Multiplication()
{
string multicipia;
cout << "How much numbers do you want?" << endl;
cin >> multicipia;
if (multicipia == "2" or "Two" or "two")
{
Calculators_Multiplication_2();
};
if (multicipia == "3" or "Three" or "three")
{
Calculators_Multiplication_3();
};
if (multicipia == "4" or "Four" or "four")
{
Calculators_Multiplication_4();
};
if (multicipia == "5" or "Five" or "five")
{
Calculators_Multiplication_5();
};
return;
}

void Calculators_Multiplication_2()
{
int multi2a;
int multi2b;
int product2;
cout << "Type in the First Number." << endl;
cin >> multi2a;
cout << "Type in the Second Number." << endl;
cin >> multi2b;
product2 = multi2a * multi2b;
cout << "The Product is " << product2 << "." << endl;
return;
}

void Calculators_Multiplication_3()
{
int multi3a;
int multi3b;
int multi3c;
int product3;
cout << "Enter the First Number!" << endl;
cin >> multi3a;
cout << "Enter the Second Number!" << endl;
cin >> multi3b;
cout << "Enter the Third Number!" << endl;
cin >> multi3c;
product3 = multi3a * multi3b * multi3c;
cout << "The Product is" << product3 << "." << endl;
return;
}

void Calculators_Multiplication_4()
{
int multi4a;
int multi4b;
int multi4c;
int multi4d;
int product4;
cout << "Enter the First Number!" << endl;
cin >> multi4a;
cout << "Enter the Second Number!" << endl;
cin >> multi4b;
cout << "Enter the Third Number!" << endl;
cin >> multi4c;
cout << "Enter the Fourth Number!" << endl;
cin >> multi4b;
product4 = multi4a * multi4b * multi4c * multi4d;
cout << "The Product of the Numbers are " << product4 << "!" << endl;
return;
}

void Calculators_Multiplication_5()
{
int multi5a;
int multi5b;
int multi5c;
int multi5d;
int multi5e;
int product5;
cout << "Enter the First Number!" << endl;
cin >> multi5a;
cout << "Enter the Second Number!" << endl;
cin >> multi5b;
cout << "Enter the Third Number!" << endl;
cin >> multi5c;
cout << "Enter the Fourth Number!" << endl;
cin >> multi5d;
cout << "Enter the Fifth Number!" << endl;
cin >> multi5e;
product5 = multi5a * multi5b * multi5c * multi5d * multi5e;
cout << "The Product of the Numbers are" << product5 << "!" << endl;
return;
}

我的部门。

#include <iostream>

using namespace std;

void Calculators_Division()
{
float divisia;
float divisiab;
float quotient;
cout << "Enter the Divisor" << endl;
cin >> divisia;
cout << "Enter the Dividend" << endl;
cin >> divisiab;
quotient = divisia / divisiab;
cout << "The Quotient of the Numbers are " << quotient << endl;
return;
}

现在的问题是,当加法完成时,减法开始。减法之后,乘​​法。乘法之后,除法。之后程序结束。对不起。只是我是编程新手(一个月左右)。

最佳答案

有很多地方需要改进(其中一些已经在评论中提到),但您的问题的确切答案是:

  • 您在 Calculators_Operation() 函数体中的 if 语句行之后有分号,这使得 if 语句无用并且您的“操作”函数每次都被调用(您已经注意到)。
  • 你以不正确的方式使用“或”运算符,如果你使用(answera ==“加法”或“+”),你基本上说:((answera ==“加法”或“+”)并且计算结果为是的(参见 here)

编辑:您的函数 Calculators_Operation 可能会更改为:

void Calculators_Operation()
{
string answera;
cout << "What Operation do you Want?" << endl;
cin >> answera;

if (answera == "Addition" || answera == "addition" || answera == "+")
{
Calculators_Addition();
}
else if (answera == "Subtraction" || answera == "subtraction" || answera == "-")
{
Calculators_Subtraction();
}
else if (answera == "Multiplication" || answera == "multiplication" || answera == "*" || answera == "x" || answera == "X")
{
Calculators_Multiplication();
}
else if (answera == "Division" || answera == "division" || answera == "/")
{
Calculators_Division();
} else {
cout << "Unknown operation entered!" << endl;
}
}

注意:您所有的 if 语句都需要根据此函数进行更改

如果有什么不起作用,请在评论中添加确切不起作用的内容,或者使用新的代码发布和问题编辑您的问题。

关于c++ - 当一个功能完成另一个功能打开时我该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44910093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com