Announcement

Collapse
No announcement yet.

Expected primary expression !!! giúp e với

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Expected primary expression !!! giúp e với

    Code e hơi dài. Bác nào giúp e với. E không hiểu tại sao lại có lỗi ở đấy.
    Nó đòi while() trước dấu } và lỗi expected primary expression cũng trước dấu }.
    Lỗi ở dòng gần cuối e đã đánh dấu.





    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <windows.h>
    #include <math.h>
    #include <stdlib.h>
    
    //globale Variablen
    int Phase1 = 0;                 //Ausgang Phase1
    int Phase2 = 0;                 //Ausgang Phase2
    int Phase3 = 0;                 //Ausgang Phase3
    int POS[] = {0,500,1000,1500,2000,2500,3000,3500,4000,4096};
    int runden(float n)           // rundungsfunktion (weil modulo nicht mit Float funktioniert)
    {
      if (n-(int)(n) >= 0.5) 
        return (int)(n+1);
       
      else
        return (int)(n);
      
    } //ende runden
    
    typedef enum {Ruhe,Links,Rechts,Stop}TSTATE; 
    TSTATE state = Ruhe;          
    
    //Main-Funktion
    int main(){
    
    unsigned int schrittwinkel = 15;
    unsigned int ausschaltwinkel = 14;    // variabel
    float a,p1;
    unsigned int aufloesung = 4096;
    float zw,KPOS1;
    int KPOS = 0;
    int i,b,c,d;
    
    a = schrittwinkel*(aufloesung/360);        // schrittwinkel
    b = ausschaltwinkel*(aufloesung/360);       // ausschaltwinkel
    c = 512;   // periode = 3*15*umrechungsfaktor = 512    
         
    //---------Endlosschleife begin------------------------------------------------------------------------------------
     while(1){
       
       switch (state) {
    		case Ruhe:   
              int j;			  
              do{         
                 printf("Drehrichtung auswählen (0 für links und 1 für rechts)");
                 scanf("%i",j);
                 if(j==0){
                 state = Links;
                 }
                 else if(j==1){
                 state = Rechts;
                 }
                 else{
                 printf("FEHLER!!! bitte nur 0 oder 1 eingeben ");
                 }
                while(j<0||j>1);
            break;    
            
            case Links :
              zw = 48+(a-b);
              for(i=0;i<=9;i++){
                 KPOS1 = POS[i] + zw;
                 KPOS = runden(KPOS1);
                 d = KPOS % c;
    
                 if(KPOS >=4096){
                 KPOS = KPOS - 4096;
                 }
    
                 printf("POS: %i\n",POS[i]);
                 printf("KPOS: %i\n",KPOS); 
                 //drehender Betrieb
    
                 if((0 <= d) && (d <= a)){
    
                 Phase1 = 0;
                 Phase3 = 0;
                 Phase2 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
    
                 if((a < d) && (d <= 2*a)){
      
                 Phase2 = 0;
                 Phase1 = 0;
                 Phase3 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
    	         
                 }  //ende if
    
                 if((2*a < d) && (d <3* a)){
     
                 Phase2 = 0;
                 Phase3 = 0;
                 Phase1 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
    	
             } //ende for
            break; 
            
            case Rechts:
              zw = 48-(a-b);
              for(i=0;i<=9;i++){
    
                 KPOS1 = POS[i] + zw;
                 KPOS = runden(KPOS1);
                 d = 512-(KPOS % c);
    
                 if(KPOS >=4096){
                 KPOS = KPOS - 4096;
                 }	
                 printf("POS: %i\n",POS[i]);
                 printf("KPOS: %i\n",KPOS);        	
         
                 //drehender Betrieb
                 
                 if((0 <= d) && (d <= a)){
                 Phase1 = 0;
                 Phase3 = 0;
                 Phase2 = 1;
    	         printf("Phase1: %i\n",Phase1);
                 printf("Phase2: %i\n",Phase2);
     	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
                 
                 if((a < d) && (d <= 2*a)){
                 Phase2 = 0;
                 Phase1 = 0;
                 Phase3 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
          	     printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 }  //ende if
    
                 if((2*a < d) && (d <3* a)){
    
                 Phase3 = 0;
                 Phase3 = 0;
                 Phase1 = 1;
                 printf("Phase1: %i\n",Phase1);
                 printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
    	
              } //ende for
            break;  
            
            case Stop:
              Phase3 = 1;
              Phase3 = 1;
              Phase1 = 1;
              printf("Phase1: %i\n",Phase1);
              printf("Phase2: %i\n",Phase2);
              printf("Phase3: %i\n",Phase3);
              printf("--------------------\n");
              Sleep(3000);
              Phase3 = 0;
              Phase3 = 0;
              Phase1 = 0;
              printf("Phase1: %i\n",Phase1);
              printf("Phase2: %i\n",Phase2);
              printf("Phase3: %i\n",Phase3);
              printf("--------------------\n");
              state = Ruhe;
              printf("***** Ruhe *****\n");
              printf("--------------------\n");
            break;
            
            default:
              state = Ruhe;
            break;
      }  // ende switch-case  
    } //ende endlos while(1)    [COLOR="#FF0000"]Lỗi ở dòng này
    [/COLOR]
    return 0;
    
    }// ende main
    [/QUOTE]

  • #2
    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <windows.h>
    #include <math.h>
    #include <stdlib.h>
    
    //globale Variablen
    int Phase1 = 0;                 //Ausgang Phase1
    int Phase2 = 0;                 //Ausgang Phase2
    int Phase3 = 0;                 //Ausgang Phase3
    int POS[] = {0,500,1000,1500,2000,2500,3000,3500,4000,4096};
    int runden(float n)           // rundungsfunktion (weil modulo nicht mit Float funktioniert)
    {
      if (n-(int)(n) >= 0.5) 
        return (int)(n+1);
       
      else
        return (int)(n);
      
    } //ende runden
    
    typedef enum {Ruhe,Links,Rechts,Stop}TSTATE; 
    TSTATE state = Ruhe;          
    
    //Main-Funktion
    int main(){
    
    unsigned int schrittwinkel = 15;
    unsigned int ausschaltwinkel = 14;    // variabel
    float a,p1;
    unsigned int aufloesung = 4096;
    float zw,KPOS1;
    int KPOS = 0;
    int i,b,c,d;
    
    a = schrittwinkel*(aufloesung/360);        // schrittwinkel
    b = ausschaltwinkel*(aufloesung/360);       // ausschaltwinkel
    c = 512;   // periode = 3*15*umrechungsfaktor = 512    
         
    //---------Endlosschleife begin------------------------------------------------------------------------------------
     while(1){
       
       switch (state) {
    		case Ruhe:   
              int j;			  
              do{         
                 printf("Drehrichtung auswählen (0 für links und 1 für rechts)");
                 scanf("%i",[B][COLOR="#FF0000"]&[/COLOR][/B]j);
                 if(j==0){
                 state = Links;
                 }
                 else if(j==1){
                 state = Rechts;
                 }
                 else{
                 printf("FEHLER!!! bitte nur 0 oder 1 eingeben ");
                 }
                [COLOR="#FF0000"][B]}[/B][/COLOR]
                while(j<0||j>1);
            break;    
            
            case Links :
              zw = 48+(a-b);
              for(i=0;i<=9;i++){
                 KPOS1 = POS[i] + zw;
                 KPOS = runden(KPOS1);
                 d = KPOS % c;
    
                 if(KPOS >=4096){
                 KPOS = KPOS - 4096;
                 }
    
                 printf("POS: %i\n",POS[i]);
                 printf("KPOS: %i\n",KPOS); 
                 //drehender Betrieb
    
                 if((0 <= d) && (d <= a)){
    
                 Phase1 = 0;
                 Phase3 = 0;
                 Phase2 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
    
                 if((a < d) && (d <= 2*a)){
      
                 Phase2 = 0;
                 Phase1 = 0;
                 Phase3 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
    	         
                 }  //ende if
    
                 if((2*a < d) && (d <3* a)){
     
                 Phase2 = 0;
                 Phase3 = 0;
                 Phase1 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
    	
             } //ende for
            break; 
            
            case Rechts:
              zw = 48-(a-b);
              for(i=0;i<=9;i++){
    
                 KPOS1 = POS[i] + zw;
                 KPOS = runden(KPOS1);
                 d = 512-(KPOS % c);
    
                 if(KPOS >=4096){
                 KPOS = KPOS - 4096;
                 }	
                 printf("POS: %i\n",POS[i]);
                 printf("KPOS: %i\n",KPOS);        	
         
                 //drehender Betrieb
                 
                 if((0 <= d) && (d <= a)){
                 Phase1 = 0;
                 Phase3 = 0;
                 Phase2 = 1;
    	         printf("Phase1: %i\n",Phase1);
                 printf("Phase2: %i\n",Phase2);
     	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
                 
                 if((a < d) && (d <= 2*a)){
                 Phase2 = 0;
                 Phase1 = 0;
                 Phase3 = 1;
                 printf("Phase1: %i\n",Phase1);
    	         printf("Phase2: %i\n",Phase2);
          	     printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 }  //ende if
    
                 if((2*a < d) && (d <3* a)){
    
                 Phase3 = 0;
                 Phase3 = 0;
                 Phase1 = 1;
                 printf("Phase1: %i\n",Phase1);
                 printf("Phase2: %i\n",Phase2);
    	         printf("Phase3: %i\n",Phase3);
    	         printf("--------------------\n");
                 } //ende if
    	
              } //ende for
            break;  
            
            case Stop:
              Phase3 = 1;
              Phase3 = 1;
              Phase1 = 1;
              printf("Phase1: %i\n",Phase1);
              printf("Phase2: %i\n",Phase2);
              printf("Phase3: %i\n",Phase3);
              printf("--------------------\n");
              Sleep(3000);
              Phase3 = 0;
              Phase3 = 0;
              Phase1 = 0;
              printf("Phase1: %i\n",Phase1);
              printf("Phase2: %i\n",Phase2);
              printf("Phase3: %i\n",Phase3);
              printf("--------------------\n");
              state = Ruhe;
              printf("***** Ruhe *****\n");
              printf("--------------------\n");
            break;
            
            default:
              state = Ruhe;
            break;
      }  // ende switch-case  
    } //ende endlos while(1)
    return 0;
    
    }// ende main
    Khoảng cách giữa bạn và ước mơ của bạn là bao xa ?

    Comment


    • #3
      cám ơn bác nhiều. E nhìn chỗ đấy mầy lần mà nhầm { của do-while và { của else.

      Comment

      LHQC

      Collapse
      Working...
      X