C 编程循环

标签 c

我正在从事的这个程序是这样的:计算你同学的平均高度。 输入以英尺和英寸为单位的高度。 验证英尺在 3-8 范围内,英寸在 0 到 <12 范围内。 显示学生人数和平均高度。 这是我到目前为止所得到的,但是,我不知道这是否是处理它的正确形式。我现在有货。

#include <stdio.h>

int main( void )
{
    char another;
    int feet;
    double inches, total = 0, average;

    printf( "Do you have a student? (y/n)" );
    scanf( "%\n%c", &another );

    while ( another == 'y' )
    {
        do
        {
            printf( "Enter inches: " );
            scanf( "%lf", &inches );
        }
        while ( inches < 0 || inches >= 12 );

        printf( "Do you have a student? (y/n)" );
        scanf( "%\n%c", &another );

    }

    return 0;
}

最佳答案

“另一个”字符的 scanf 格式应该是“%c”。否则,它对我来说看起来是正确的。

关于C 编程循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21892141/

相关文章:

c - 无法读取 C 中的 token

C 编程 : How do I read terminal input if piping from stdin?

c - CodeBlocks 中的奇怪警告 - C

c - 一种用互斥量同步读取和修改的方法

c++ - 为什么 C++ Hello World 二进制文件比等效的 C 二进制文件大?

c - 具有双指针的 Malloc 结构

c - 如何在 C 中打印 errno 的符号名称?

c++ - 我使用什么 C/C++ 库来更改 Windows 中的 HTTP 数据包?

c - C 中的指针和内存混淆

c - 在 C 编程中存储系统调用