【发布时间】:2011-06-19 19:11:59
【问题描述】:
我是 C++ 的新手,我正在尝试制作一个“计算器”:将两个数字相加,两个数字相减,两个数字相乘,两个数字相除,取一个数字的正弦,取一个的余弦数字,或取数字的正切。这是代码:
#include <iostream>;
#include <cmath>;
#include <string>
int main ()
{}
int ask(std::string operation);
{
std::cout<<"Type Addition, Subtraction, Multiplication, Division, Sine, Cosine, or Tangent:\n";
std::cin>>operation;
if (operation="Addition")
{
goto Add
}
float Add(float addend1, float addend2, float answer)
{
Add:
std::cout<<"Insert the first number to be added:\n";
std::cin>>addend1;
std::cout << "Insert the second number to be added:\n";
std::cin>>addend2;
answer=addend1+addend2;
std::cout<<addend1<<"+"<<addend2<<"="<<answer<<"\n";
break
}
}
以后会有更多的功能,但是我的问题在第7行。有一个错误说:expected unqualified-id before "{" token。我知道我的缩进很糟糕,但是谢谢!
【问题讨论】:
-
为什么...为什么...为什么
goto?!此外,标签在另一个函数中。非常非常糟糕的主意。你用的是什么编译器? -
在
if条件下注意=与==。 -
@Woobie:OP 也不想要
==,他想要strcmp。 -
哇,这是我见过的最糟糕的代码。我看过很多 CS 101 代码。几年前我曾经是个非官方的助教。
-
@Omnifarious:每个人都从某个地方开始。
标签: c++ compiler-errors token