#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 ++的菜鸟 编码所以请帮忙! 我做了自己的研究而找不到它。
答案 0 :(得分:3)
你不能说像
这样的东西else(value1 = +)
在C ++中。你必须提出别的意思,但很难猜到是什么,因为你的代码中有很多错误。通常,您不能只输入随机字符并期望一个正常运行的程序。
答案 1 :(得分:2)
错误源于{ ... }
函数之后的其他main
块,因为编译器不知道如何处理声明之外的代码。但这不是您的代码唯一的问题:
if
语句后直接放置分号表示“如果条件为真,则无论如何都不执行任何操作”,并且下一个语句将以任一方式执行。if(value = +)
应为if(value == '+')
等 - 您将关联=
与比较==
混合在一起,另外您尝试使用运算符+
而不是字符{ {1}} * '+'
应该做什么?代码块放在else(something)
s中,而不是{}
s 我建议您开始使用像Python这样的简单语言进行编程吗?它有意义的缩进和缺乏分号使生活变得更加容易......
答案 2 :(得分:1)
摆脱所有
}
{
您将能够继续修复下一个错误。
当您编写如下大括号时:}
您正在关闭代码块,在这种情况下是您的主要功能。
当您撰写以下内容时:{
编译器认为你正在尝试启动一个新函数,但是没有函数签名而你会收到错误。
在我看来,您希望所有这些代码都在您的main函数中,因此您需要类似以下内容:
int main()
{
//insert all of your code here
return 0;
}