Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么我运行这个程序时总是得到一个空表?_C_Loops_While Loop - Fatal编程技术网

C 为什么我运行这个程序时总是得到一个空表?

C 为什么我运行这个程序时总是得到一个空表?,c,loops,while-loop,C,Loops,While Loop,这是我写的。我猜这可能与我的while循环的逻辑有关,但我不能完全发现它!感谢您的帮助!谢谢 #include <stdio.h> #include <math.h> //Open main function. int main(void) { double new_area, area_total = 14000, area_uncut = 2500, rate = 0.02, years; int count = 0; printf("Th

这是我写的。我猜这可能与我的
while
循环的逻辑有关,但我不能完全发现它!感谢您的帮助!谢谢

#include <stdio.h>
#include <math.h>

//Open main function.
int main(void)
{
    double new_area, area_total = 14000, area_uncut = 2500, rate = 0.02, years;
    int count = 0;

    printf("This program is written for a plot of land totaling 14000 acres,    "
           "with 2500 acres of uncut forest\nand a reforestation rate "
           "of 0.02. Given a time period (years) this program will output a table\n"
           "displaying the number acres reforested at the end of "
           "each year.\n\n\n");

    printf("Please enter a value of 'years' to be used for the table.\n"
           "Values presented will represent the number acres reforested at the end of "
           "each year:>> ");

    scanf("%lf", &years);

    years = ceil(years);

    printf("\n\nNumber of Years\t\tReforested Area");

    while (count <= years);
    {
        count = count + 1;
        new_area = area_uncut + (rate * area_uncut);
        printf("\n%1.0lf\t\t\t%.1lf", count, area_uncut);
        area_uncut += new_area;
    }

    return 0;
}
#包括
#包括
//打开主功能。
内部主(空)
{
双倍新面积,总面积=14000,未切割面积=2500,比率=0.02,年;
整数计数=0;
printf(“本程序是为一块总面积为14000英亩的土地编写的,”
“有2500英亩未开垦的森林\n和重新造林率”
“0.02。给定一个时间段(年),此程序将输出一个表\n”
“显示结束时重新造林的英亩数”
“每年。\n\n\n”);
printf(“请输入用于表的“年”值。\n”
“提供的值将代表在2010年底重新造林的英亩数”
“每年:>>”;
scanf(“%lf”、&years);
年=ceil(年);
printf(“\n\n年数\t\t森林面积”);

while(计数这行末尾有一个额外的
:while(计数这行末尾有一个额外的
while(计数
while(count@KeineLust这就是为什么它是一个警告,而不是一个错误。这是一个常见的打字错误,编译器会发出警告,以防它不是你真正的意思。你启用了什么标志来接收这样的警告?@Barmar:我用
g++
-Wall
编译,但它没有显示出来。我仍然高估了你的评论,因为删除分号修复了Ps问题。当我尝试使用
gcc
编译时,由于
ceil
,我得到一个错误。gcc在Linux上忽略了这个标志:(
而(count@KeineLust这就是为什么它是一个警告,而不是一个错误。这是一个常见的打字错误,编译器会发出警告,以防它不是你真正的意思。你启用了什么标志来接收这样的警告?@Barmar:我用
g++
-Wall
编译,但它没有显示出来。我仍然高估了你的评论,因为删除分号修复了Ps问题。当我尝试使用
gcc
编译时,由于
ceil
,我收到一个错误。在Linux上,gcc忽略了这个标志:(
while (count <= years) {
    count = count + 1;
    new_area = area_uncut + (rate * area_uncut);
    printf("\n%d\t\t\t%.1f", count, area_uncut);
    area_uncut += new_area;
}