我得到错误“错误:预期表达之前'! ='令牌 [英] Im getting the error "error: expected expression before '! =' token

查看:87
本文介绍了我得到错误“错误:预期表达之前'! ='令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c编程的初学者。

在下面的程序中检查一年是否是闰年,我在编译期间不断收到上述错误

我的条件逻辑:

如果年份可被4整除
1.如果年份不能被100整除则是闰年。它不是闰年)

2.如果年份可以被100整除,那么它必须可以被400整除。



有人可以检查逻辑/语法错误并向我解释一下吗?

非常感谢。



我尝试过:



 #include< stdio.h> 
int main()
{
int y;
printf(输入年份);
scanf(%d,& y);

if(y%4 == 0)
{
if(y%100 =!= 0)

printf(闰年 );
else
printf(不是闰年。);}

其他
{
if(y%100 == 0)
{
if(y%400 == 0)
printf(闰年);
else
printf(不是闰年);}}

返回0;}

解决方案

这不存在

 如果 (y%100 =!=  0 



它是

< pre lang =c ++> if (y%100!= 0





  if (y%100 ==  0 





建议:学会正确缩进代码,显示其结构和它有助于阅读和理解。

  #include   <   stdio.h  >  
int main()
{
int y;
printf( 输入年份);
scanf( %d,& y);

if (y%4 == 0
{
if (y%100 =!= 0

printf( 闰年);
else
printf( 不是闰年。);
}
else
{
if (y %100 == 0
{
if (y%400 == 0
printf( 闰年 );
else
printf( 不是闰年);
}
}

返回 0 ;
}



专业程序员的编辑器具有此功能,其他功能包括括号匹配和语法高亮。

Notepad++主页 [ ^ ]

ultraedit [ ^ ]



在阅读代码时,可以看到逻辑是错误。



[更新]

您需要学习如何编写伪代码

伪代码 - 维基百科 [ ^ ]

Quote:

1。如果年份不能被100整除,则为闰年。(否则不是闰年)

2.如果年份可以被100整除,那么闰年它也必须是可整除的400.



因为1.和2.是自相矛盾的。

通过编程,你需要格外小心一切,嵌套,结构


I'm a beginner in c programming.
In the following program to check whether or not a year is a leap year, I keep getting the above mentioned error during compilation
my logic for the conditions:
if the year is divisible by 4
1. if the year is not divisible by 100 it is a leap year.(otherwise its not a leap year)
2. if the year is divisible by 100,to be a leap year it must also be divisible by 400.

Could someone please check the logic/syntax errors and explain them to me?
Much obliged thanks.

What I have tried:

#include <stdio.h>
int main()
{
int y;
printf("enter the year");
scanf("%d",&y);

  if(y%4==0)
{
   if(y%100=!=0)

     printf("Leap Year");
  else
    printf("Not a Leap year.");}

else
{
  if(y%100==0)
  {
    if(y%400==0)
    printf("Leap year");
else
    printf("Not a Leap Year");}}

    return 0;}

解决方案

This does not exist

if(y%100=!=0)


it is either

if(y%100!=0)


or

if(y%100==0)



Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding.

#include <stdio.h>
int main()
{
  int y;
  printf("enter the year");
  scanf("%d",&y);

  if(y%4==0)
  {
    if(y%100=!=0)

      printf("Leap Year");
    else
      printf("Not a Leap year.");
  }
  else
  {
    if(y%100==0)
    {
      if(y%400==0)
        printf("Leap year");
      else
        printf("Not a Leap Year");
    }
  }

  return 0;
}


Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]

On reading the code, one can see that the logic is wrong.

[Update]
You need to learn how to write pseudo code
Pseudocode - Wikipedia[^]

Quote:

1. if the year is not divisible by 100 it is a leap year.(otherwise its not a leap year)
2. if the year is divisible by 100,to be a leap year it must also be divisible by 400.


As is 1. and 2. are self contradictory.
With programming, you need to be extra careful about position of everything, nesting, structure.


这篇关于我得到错误“错误:预期表达之前'! ='令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆