2016-09-18 60 views
-1

在這裏,我得到元音的答案,但不是繼續它說錯誤的繼續和休息。我正在學習C語言,但我不能運行'y'來繼續程序

#include <stdio.h> 
    main() { 
    char c, d; 
    printf("say your word to find the vowels\n"); 
    scanf("%c", & c); 
    if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U') 
     printf("you got a vowel\n"); 
    else 
     printf("cool no vowel word\n"); 
    printf("continue\n"); 
    printf("(y/n)\n"); 
    scanf("%c", & d); 
    if (d == 'y' || d == 'Y') 
     continue; 
    else 
     break; 
    return 0; 
    } 

回答

0

繼續和破壞在循環塊中工作..但在這裏你沒有在循環中加入它們。把整個if塊在while(1),也將努力

#include <stdio.h> 

int main() 
{ 
    char c; 
    int d; 
    while (1) { 
     printf("say your word to find the vowels\n"); 
     scanf("%c", &c); 

     if (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U') 
      printf("you got a vowel\n"); 
     else 
      printf("cool no vowel word\n"); 

     printf("To continue enter 1\n"); 
     scanf("%d", &d); 

     if (d == 1) 
      continue; 
     else 
      break; 
    } 
    return 0; 
} 

檢查繼續下面的鏈接break語句的語法。

https://www.codingunit.com/c-tutorial-for-loop-while-loop-break-and-continue

+0

'while(true)'better better? –

+0

當然!如果編譯器對此感到滿意。 – Shaggy

+0

代碼的縮進可以改進。 – alk

2
if (d == 'y' || d == 'Y') 
    continue; // where? 
else 
    break;  // what? 

您的主要功能沒什麼continuebreak

兩個continuebreak只有一個循環內是有意義的,所以你應該main()添加while(true)循環圍繞代碼重複整個事情,直到用戶決定退出。