-5
#include <iostream>

using namespace std;

int num1, num2, num3, num4, num5, result, result1, result2, result3, value, cont;
//number user enters/variable
int main()
{
    cout << "please enter the operation,+ for addtion,- for subtaction,* for multiplatcion,/ for division"
    ;cin >> value
    ;cout << "please enter the first number number:";

    cin >> num1
    ;cout << "please enter the second number: ";
    cin >> num2

    ;if(value == '+' )
    ;result = num1 + num2;
    cout << num1 << " plus " << num2 << " is equal to: " << result << ".\n";
    if(value = '-' )
    ;result = num1 - num2;
    cout << num1 << " minus " << num2 << " is equal to: " << result << ".\n";
    if(value = '*' )
    ;result = num1 * num2;
    cout << num1 << " times " << num2 << " is equal to: " << result << ".\n";
    if(value = '/' )
    ;result = num1 / num2;
    cout << num1 << " divided by " << num2 << " is equal to: " << result << ".\n";



}
{
    cout << "press 1 to enter more numbers, or press 0 to not"
    cin >> cont
    if(cont = 1)
    cout << "please enter the operation,+ for addtion,- for subtaction,* for multiplatcion,/ for division"
    cin >> value1
    cout << "please enter the next number:";
    cin num3

    else(cont = 0)

    else(value1 = +)
    ;result1 = result + num3;
    cout << result << " plus " << num3 << " is equal to: " << result1 << ".\n";
    else(value1 = -)
    ;result1 = result - num3
    cout << result << " minus " << num3 << " is equal to: " << result1 << ".\n";
    else(value1 = *)
    ;result1 = result * num3
    cout << result << " times " << num3 << " is equal to: " << result1 << ".\n";
    else(value1 = /)
    ;result1 = result / num3
    cout << result << " divided by " << num3 << " is equal to: " << result1 << ".\n";



}
{
    cout << "press 1 to enter more numbers, or press 0 to not"
    cin >> cont
    if(cont = 1)
    cout << "please enter the operation,+ for addtion,- for subtaction,* for multiplatcion,/ for division"
    cin >> value1
    ;cout << "please enter the next number: ";
    cin >> num4
    else(cont = 0)

    else(value2 = +)
    ;result2 = result1 + num4;
    cout << result1 << " plus " << num4 << " is equal to: " << result2 << ".\n";
    else(value2 = -)
    ;result2 = result1 + num4;
    cout << result << " minus " << num3 << " is equal to: " << result1 << ".\n";
    else(value2 = *)
    ;result2 = result1 * num4
    cout << result << " times " << num3 << " is equal to: " << result1 << ".\n";
    else(value2 = /)
    ;result2 = result1 / num4
    cout << result << " divided by " << num3 << " is equal to: " << result1 << ".\n";





{
    cout << "press 1 to enter more numbers, or press 0 to not"
    cin >> cont
    if(cont = 1)
   cout << "enter the operation,+ for addtion,- for subtaction,* for multiplatcion,/ for division"
    cin >> value2
    ;cout << "please enter the next number: ";
    cin >> num5

    if(value3 = +)
    ;result3 = result2 + num5;
    cout << result2 << " plus " << num5 << " is equal to: " << result3 << ".\n";
    else(value3 = -)
    ;result3 = result2 - num5
    cout << result << " minus " << num3 << " is equal to: " << result1 << ".\n";
    else(value3 = *)
    ;result3 = result2 * num5
    cout << result << " times " << num3 << " is equal to: " << result1 << ".\n";
    else(value3 = /)
    ;result3 = result2 / num5







    return 0;

错误发生在第 34 行,它显示 { 所以请帮助我!该代码用于基本计算器,如果您可以更正第 34 行,请随意使用它!我不知道是什么原因造成的,我是 C++ 编码的菜鸟,所以请帮忙!我自己研究过,找不到。

4

3 回答 3

3

你不能说像

else(value1 = +)

在 C++ 中。你一定是别的意思,但很难猜出是什么,因为你的代码中有很多错误。通常,您不能只键入随机字符并期望一个正常运行的程序。

于 2013-10-15T15:12:05.637 回答
2

该错误源于函数{ ... }后面的附加块main,因为编译器不知道如何处理声明之外的代码。但这不是您的代码的唯一问题:

  • 将分号直接放在if语句之后意味着“如果条件为真,则什么也不做”,并且下一条语句以任何一种方式执行。
  • if(value = +)应该是if(value == '+')等等-您将关联=与比较混合在一起==,再加上您尝试使用运算符+而不是字符'+'*else(something)应该做什么?代码块放在{}s 中,而不是()s

我可以建议您开始使用 Python 等更简单的语言进行编程吗?它有意义的缩进和没有分号使生活变得更轻松......

于 2013-10-15T15:25:37.973 回答
1

摆脱所有的

}
{

并且您将能够继续修复您的下一个错误。


当您编写如下大括号时:}

你正在关闭你的代码块,在这种情况下是你的主要功能。

当您编写以下内容时:{

编译器认为您正在尝试启动一个新函数,但没有函数签名并且您收到错误消息。


在我看来,您希望所有这些代码都在您的 main 函数中,因此您需要以下内容:

int main()
{ 
    //insert all of your code here
    return 0;
}
于 2013-10-15T15:10:57.467 回答