2016-09-18 33 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)循环围绕代码重复整个事情,直到用户决定退出。

相关问题