作者 主題: CPP錯誤 [Error] expected ';' before ')' token  (閱讀 15975 次)

0 會員 與 1 訪客 正在閱讀本文。

hointw

  • 可愛的小學生
  • *
  • 文章數: 2
    • 檢視個人資料
我不知道哪裡編錯了
http://zerojudge.tw/ShowProblem?problemid=a263
#include <iostream>
#include<stdio.h>

int main(){
   int daysOfMonth[13]={31,31,28,31,30,31,30,31,31,30,31,30,31};
   int y0,y1,m0,m1,d0,d1,days,daysInYear0,daysInYear1;
   while (scanf("%d%d%d%d%d%d",&y0,&m1,&d0,&y1,&m1,&d1)!=EOF){
      if(y0*10000+m0*100+d0>y1*10000+m1*100+d1){
         int k;
         k=y0,y0=y1,y1=k;
         k=m0,m0=m1,m1=k;
         k=d0,d0=d1,d1=k;
      }
      days = 0,daysInYear0=0,daysInYear1=0;     
      for(;y1==y0;y0++)
         days+=y0%4?365:y0%100?366:y0%400?365:366;
      daysOfMonth[2]=y0%4?28:y0%100?29:y0%400?28:29;
      for (int i=1 ;i<=m0-1,i++)
         daysInYear0+=daysOfMonth;
      for (int i=1 ;i<=m0-1;i++)
         daysInYear1+=daysOfMonth;
      daysInYear0+=d0;
      daysInYear1+=d1;
      days+=daysInYear1-daysInYear0;
      printf("%d\n",days);
   
      //for(;y1!=y0;y0++)   
      //   daysInYear0+=day
      }
   }
我是照https://www.livecoding.tv/yuminhuang/videos/YvQk3-solving-problem-basic-but-in-chinese
的人做的
« 上次編輯: 2016-04-15 12:04 由 hointw »

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
Re: 請問怎麼會error 24[Error] expected ')' b
« 回覆 #1 於: 2016-04-14 18:40 »
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>


int main (int argc,char *argv[])
{

   float a , b, c;
   printf("PL IN A_side" : ) ;
   scanf("%f",&a);
   printf("PL IN B_side");
   scanf("%f",&b);
   printf("PL IN C_side");
   scanf("%f",&c);
   if ((pow(a,2)+pow(b,2))==pow(c,2)||
      ((pow(a,2)+pow(c,2))==pow(b,2)||
      ((pow(b,2)+pow(c,2))==pow(a,2))
      printf("\nThis is Trigle");
   else
   
      printf("Not Trigle");
   system("PAUSE");
   return 0;
      }
http://i.imgur.com/FN0EB4o.png

error 1: 冒號刪除,或是放引號裡
error 2: if 前兩個等於判斷,後面少了  )
error 3, 4: e 2 修正了應該就沒了

hointw

  • 可愛的小學生
  • *
  • 文章數: 2
    • 檢視個人資料
Re: 請問怎麼會error 24[Error] expected ')' b
« 回覆 #2 於: 2016-04-14 19:09 »
THX ,這麼快有回復
這是把: 收進 ""內 IF 增加)  剩下的問題

這一題也想問, 不知道會不會違規

//5-26
#include<stdio.h>
#include<stdlib.h>

int main(int argc[])
{
   int income,tax, discount=0;
   double taxrate=0.0;
   printf("Plz In gTax");
   scanf("%d",&income);
   if(income>=52000 && income<=1170000)
   {
      discount=36400;
      taxrate=0.12;
   }
   else if(income>=0 && income<=52000)
   {
      discount=0;
      taxrate=0;
   
   }else if(income>=117000 && income<=2350000)
   {
      discount=130000;
      taxrate=0.20;
   }
   else if(income>=2350000 && income<=4400000)
   {
      discount=365000;
      taxrate=0.3;
   }
   else if(income>=4400000 )
   {
      discount=805000;
      taxrate=0.4;
   }
   else
   {
      printf("Plz IN >0 int");
      system("PAUSE");
      exit(0);
   }
   tax=income*taxrate;
   printf("/n");
   printf("Gtax:%d Yen"\n,income);
   printf("Gtax A:%2.0f%"\n,taxratr*100);
   printf("=================");
   printf("Gtax B:%d\n",tax);
   printf("Gtax C:%d\n",discount);
   printf("=================");
   printf("This Year Gtax:%d Yen"\n,tax-discount);
   printf("\n\n");
      system("PAUSE");
      return(0);
}

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
Re: 請問怎麼會error 24[Error] expected ')' b
« 回覆 #3 於: 2016-04-14 20:22 »
if 判斷式最外層少了一組括號

代碼: [選擇]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main (int argc,char *argv[]) {
   float a , b, c;
   printf("PL IN A_side: ");
   scanf("%f", &a);
   printf("PL IN B_side: ");
   scanf("%f", &b);
   printf("PL IN C_side: ");
   scanf("%f", &c);
   
   if (((pow(a,2)+pow(b,2))==pow(c,2)) ||
    ((pow(a,2)+pow(c,2))==pow(b,2)) ||
    ((pow(b,2)+pow(c,2))==pow(a,2))) {
    printf("\nThis is Trigle");
   } else {
     printf("Not Trigle\n");
   }

   system("PAUSE");
   return 0;
}

引用
$ clang -lm -o 5-7 5-7.c
$ ./5-7
PL IN A_side: 3
PL IN B_side: 5
PL IN C_side: 7
Not Trigle
Press any key to continue...
$

5-26 的問題是.... \n 都跑到引號外了啊
« 上次編輯: 2016-04-14 20:24 由 Yamaka »