深夜敲了个代码,可是有错误,眼皮打架要睡觉啊,哪位能帮我看看吗
#include<stdio.h>#include<stdbool.h>
int get_int();
bool bad_limits(int begin,int end,int low,int high);
double sum_squares(int a,int b);
int main()
{
const int MIN=-1000;
const int MAX=+1000;
int start;
int stop;
double answer;
printf("This program computes the sum of the squares of "
"integers in a range.\nThe lower bound should not "
"be less than -1000 and \nthe upper bound should not"
"be more than +1000\nEnter the limits(enter 0 for "
"both limmits to quit):\nlower limit:");
start=get_int();
printf("upper limit:");
stop=get_int();
while(start!=0||stop!=0)
{
if(bad_limits(start,stop,MIN,MAX))
printf("Please try again.\n");
else{
answer=sum_squares(start,stop);
printf("The sum of the squares of the integers from");
printf(" %d to %d is %g\n",start,stop,answer);
}
printf("Enter the limits(enter 0 for both to quit):\n");
printf("lower:\n");
start=get_int();
printf("upper limit:");
stop=get_int();
}
printf("Done.");
return 0;
}
int get_int()
{
int input;
char ch;
while(scanf("%d",&input)!=1)
{
while((ch=getchar())!='\n')
putchar();
printf("is not an ingeter.\nPlease enter an\
ingeter value,such as 25,-178,or 3:");
}
return input;
}
double sum_square(int a,int b)
{
double total=0;
int i;
for(i=a;i<=b;i++)
total+=i*i;
return total;
}
bool bad_limits(int begin,int end,int low,int high)
{
bool not_good=false;
if(begin>end)
{
printf("$d isn't smaller than %d.\n",begin,end);
not_good=true;
}
if(begin<low||end<low)
{
printf("value must be %d or greater.",low);
not_good=true;
}
if(begin>high||end>high)
{
printf("Value must be %d or less.\n",high);
not_good=true;
}
return not_good;
}
C支持stdbool.h吗C是没有BOOL布尔类型的 C++才有啊 太长了,看得我也想睡了 牡丹花下死做鬼 发表于 2013-8-26 23:31 static/image/common/back.gif
C支持stdbool.h吗C是没有BOOL布尔类型的 C++才有啊
c是支持stdbool.h这个头文件的,#include<stdio.h>
int main()
#include<stdbool.h>
{
long num;
long sum=0L;
bool input_is_good;
printf("Please enter an integer to be summed.");
printf("(q to quit): ");
input_is_good=scanf("%ld",&num)==1;
while(input_is_good)
{
sum=sum+num;
printf("Please enter next integer(q to quit):");
input_is_good=scanf("%ld",&num)==1;
}
printf("Those integers sum to %ld.\n",sum);
return 0;
}
诸葛暗 发表于 2013-8-27 08:09 static/image/common/back.gif
c是支持stdbool.h这个头文件的,#include
int main()
#include
→_→ C语言是没有BOOL 这个类型的 啊 诸葛暗 发表于 2013-8-27 08:09 static/image/common/back.gif
c是支持stdbool.h这个头文件的,#include
int main()
#include
还有就是你没有这个头文件看看你VC的地方有没有吧 我找到了,一共三处,第一处,while((ch=getchar())!='\n')
putchar();
这里的putchar()应该是putchar(ch)
第二处,printf("$d isn't smaller than %d.\n",begin,end);
转换说明符应该是%d:sweat:
第三处,double sum_square(int a,int b)
这里定义错了,应该定义double sum_squares(int a,int b)
:lol:早起看了看,终于找到了
诸葛暗 发表于 2013-8-27 08:09 static/image/common/back.gif
c是支持stdbool.h这个头文件的,#include
int main()
#include
我这里就没有这个文件所以我就算是.cpp照样出错
页:
[1]