【发布时间】:2013-11-09 17:09:31
【问题描述】:
我收到了这个错误
error C2059: syntax error : 'if'
这是我的代码
// N.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int main ()
{
int x,y,n,i,m;
std::cout<<"please enter a number";
i=0;
std::cin>>n;
for (x=1;x=n;x++)
for (y=1;y=n;y++)
if (x=y) m=x;
else;
while (x!=y) ;
do
{
if (x>y) x=x-y;
else y=y-x;
m=x;
}
if (m=1) i=i+1;
std::cout<<i;
return 0;
}
有什么问题?
我正在使用 microsoft visual studio 2008
【问题讨论】:
-
查找几乎所有内容的语法可能是个好主意。提示:可以是
while( cond ) { .. }或do { ... } while( cond )。 -
... 也是
if (x==y)而不是if (x=y)和if (m=1)类似... -
为什么
else是空的?你为什么不缩进? -
在每个
for、if和while之后使用大括号、{}。牙套是你的朋友。它们将有助于推广具有更少错误的高质量代码。
标签: c++ visual-c++